Can someone please help!
How can I highlight all web elements in following class during test execution in WebDriver? With Selenium RC, it was quite straight forward
I am using ExtentReport as a report tool and I am adding images in the failed test steps as a base64 format, which allows me to display them right after the text in the output report. When I am taking screenshots and want to highlight element(s) in order to be more visible in the screenshot I am using the following method to highlight -> screenshot -> un-highlight.
private void highlightElement(WebElement elemToHighlight) {
if (_driver instanceof JavascriptExecutor) {
((JavascriptExecutor) _driver).executeScript("arguments[0].style.border='3px solid red'", elem);
}
}
public String addScreenshotToHTML(WebElement... elmsToHighlight) {
String result;
List initStyle = new ArrayList<>();
if (elmsToHighlight.length > 0) {
for (WebElement elem : elmsToHighlight) {
initStyle.add(elem.getCssValue("border"));
highlightElement(elem);
}
}
String screenshot = ((TakesScreenshot) _driver).getScreenshotAs(OutputType.BASE64);
// NOTE: add the
tag content between the tags with the Base64 image
//
result = "
";
if (elmsToHighlight.length > 0) {
for (WebElement elem : elmsToHighlight) {
jsExec().executeScript("arguments[0].style.border='" + initStyle.get(0) + "'", elem);
initStyle.remove(0);
}
}
return result;
}
Hope that helps