package com.javascript.example; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.testng.annotations.Test; import utility.Helper; public class ElementHighlighter { @Test public void highlightElement() throws Exception{ WebDriver driver = Helper.launchBrowser("chrome"); driver.get("http://facebook.com"); JavascriptExecutor js = ((JavascriptExecutor)driver); /*js.executeScript("document.getElementById('email')" + ".setAttribute('style','background-color: yellow; border: 2px solid red;')");*/ WebElement element = driver.findElement(By.id("email")); js.executeScript("arguments[0]" + ".setAttribute('style','background-color: yellow; border: 2px solid red;')",element); Thread.sleep(1000); element.sendKeys("9019352434"); js.executeScript("arguments[0]" + ".setAttribute('style','border: 2px solid white;')",element); Thread.sleep(3000); driver.close(); } @Test public void highlightElementNew() throws Exception{ WebDriver driver = Helper.launchBrowser("chrome"); driver.get("http://facebook.com"); JavascriptExecutor js = ((JavascriptExecutor)driver); WebElement element = (WebElement) js.executeScript("return document.getElementById('email')"); Helper.highlightElement(driver, element); element.sendKeys("9019352434"); element = (WebElement) js.executeScript("return document.getElementById('pass')"); Helper.highlightElement(driver, element); element.sendKeys("password123"); element = (WebElement) js.executeScript("return document.getElementById('loginbutton')"); Helper.highlightElement(driver, element); element.click(); Thread.sleep(3000); driver.close(); } }
Elements Highlighter in Selenium WebDriver using JavascriptExecutor Interface
Subscribe to:
Posts (Atom)
No comments:
Post a Comment