WebElement object to highlight elements:
During test execution, there is no way to highlight an element. This will help us to see what is
actually going on in the browser. This method will slow down the tests a bit, but sometimes it's
a useful way to debug tests.
In this recipe, we will create an extension for WebElement and provide the highlight
Elements() method at runtime.
Sample Code as below:
WebElement username= driver.findElement(By.className("Value"));
WebElement password= driver.findElement(By.id("Value"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].setAttribute('style', arguments[1]);", username, "color: blue; border: 2px solid blue;");
jse.executeScript("arguments[0].setAttribute('style', arguments[1]);", password, "color: yellow; border: 0px solid red;");
During test execution, there is no way to highlight an element. This will help us to see what is
actually going on in the browser. This method will slow down the tests a bit, but sometimes it's
a useful way to debug tests.
In this recipe, we will create an extension for WebElement and provide the highlight
Elements() method at runtime.
Sample Code as below:
WebElement username= driver.findElement(By.className("Value"));
WebElement password= driver.findElement(By.id("Value"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].setAttribute('style', arguments[1]);", username, "color: blue; border: 2px solid blue;");
jse.executeScript("arguments[0].setAttribute('style', arguments[1]);", password, "color: yellow; border: 0px solid red;");
0 Comments