How to highlight elements in Selenium Webdriver:
========================================
We can highlight the elements in Selenium Webdriver by taking support of JavascriptExecutor interface.
This interface is having one method called executeScript(--),by usiu=ng this method we can highlate the elements when the action is performing
//sample example
----------------------
package files;
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 HighLateDemo {
public static void main(String []args) throws InterruptedException{
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://www.gmail.com");
JavascriptExecutor js=(JavascriptExecutor)driver;
WebElement username= driver.findElement(By.id("Email"));
js.executeScript("arguments[0].style.border='4px groove green'", username);
username.sendKeys("rameshat914@gmail.com");
WebElement next = driver.findElement(By.id("next"));
js.executeScript("arguments[0].style.border='4px groove green'", next);
next.click();
Thread.sleep(3000);
WebElement password = driver.findElement(By.id("Passwd"));
js.executeScript("arguments[0].style.border='4px groove green'", password);
password.clear();
password.sendKeys("selenium");
WebElement signin = driver.findElement(By.id("signIn"));
js.executeScript("arguments[0].style.border='4px groove green'", signin);
signin.click();
driver.quit();
}
}
========================================
We can highlight the elements in Selenium Webdriver by taking support of JavascriptExecutor interface.
This interface is having one method called executeScript(--),by usiu=ng this method we can highlate the elements when the action is performing
//sample example
----------------------
package files;
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 HighLateDemo {
public static void main(String []args) throws InterruptedException{
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://www.gmail.com");
JavascriptExecutor js=(JavascriptExecutor)driver;
WebElement username= driver.findElement(By.id("Email"));
js.executeScript("arguments[0].style.border='4px groove green'", username);
username.sendKeys("rameshat914@gmail.com");
WebElement next = driver.findElement(By.id("next"));
js.executeScript("arguments[0].style.border='4px groove green'", next);
next.click();
Thread.sleep(3000);
WebElement password = driver.findElement(By.id("Passwd"));
js.executeScript("arguments[0].style.border='4px groove green'", password);
password.clear();
password.sendKeys("selenium");
WebElement signin = driver.findElement(By.id("signIn"));
js.executeScript("arguments[0].style.border='4px groove green'", signin);
signin.click();
driver.quit();
}
}
No comments:
Post a Comment