Highlight Element(Select locator) on a page:
package test ;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class HighlightElement {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\Drive\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.get("https://www.google.com");
1. WebElement searchBox = driver.findElement(By.xpath("//input[@aria-label='Search']"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].style.border='2px solid red'", searchBox);
2. WebElement searchBox = driver.findElement(By.xpath("//input[@aria-label='Search']"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].style.background='yellow'", searchBox);
3. WebElement searchBox = driver.findElement(By.xpath("//input[@aria-label='Search']"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].setAttribute('style', 'border:2px solid red; background:yellow')", searchBox);
4. driver.findElement(By.xpath("//input[@id='gbqfbb']")).sendKeys("");
}
}
No comments:
Post a Comment