Friday, March 22, 2019

Highlight elements in Selenium Webdriver



 package learning;  
 import org.openqa.selenium.JavascriptExecutor;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.WebElement;  
 public class Hightlight {  
      public static void hilightElement(WebElement element, WebDriver driver) {  
           for (int i = 0; i < 2; i++) {  
                JavascriptExecutor js = (JavascriptExecutor) driver;  
                js.executeScript("arguments[0].setAttribute('style', 'background: yellow; border: 2px solid red;');",  
                          element);  
           }  
      }  
 }  


 package learning;  
 import org.openqa.selenium.By;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.WebElement;  
 import org.openqa.selenium.chrome.ChromeDriver;  
 import org.testng.annotations.Test;  
 public class HilightExample {  
      @Test  
      public void showIt() {  
           System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");  
           WebDriver driver = new ChromeDriver();  
           driver.manage().window().maximize();  
           driver.get("https://www.flipkart.com/");  
           WebElement element = driver.findElement(By.className("_2zrpKA"));  
           Hightlight.hilightElement(element, driver);  
           element.sendKeys("hulagabal@gmail.com");  
      }  
 }  

No comments:

Post a Comment