How to highlight an element using selenium webdriver

Script to highlight element border

Script1:-

package selenium_examples;


import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class Sample {

public static void main(String[] args)
{

WebDriver driver = new FirefoxDriver();
       driver.get("http://www.seleniumhq.org/");
       driver.manage().window().maximize();
      WebElement element = driver.findElement(By.name("q"));
       JavascriptExecutor js = (JavascriptExecutor)driver;
       js.executeScript("arguments[0].style.border='5px solid blue'", element);
       }
}

Above script highlights search textbox border in www.seleniumhq.org website.

highlight element in selenium webdriver



Script2:-

package selenium_examples;


import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class Sample {

public static void main(String[] args)
{

WebDriver driver = new FirefoxDriver();
       driver.get("https://www.google.co.in/");
       driver.manage().window().maximize();
      WebElement element = driver.findElement(By.name("btnK"));
       JavascriptExecutor js = (JavascriptExecutor)driver;
       js.executeScript("arguments[0].style.border='5px solid red'", element);
       }
}



 


No comments:

Related Posts Plugin for WordPress, Blogger...

Fun and Knowledge