domingo, 31 de enero de 2016

Selenium / Java - How to draw a rectangle to highlight an element of a screen

Hello!
This trick is awesome when you're trying to identify objects in a webpage while automating a test case.
Basically, we need to select a color and also the number of pixels that the rectangle will have.
The following line makes the trick:

WebElement elem = driver.findElement(By.xpath("XPATH"));
if (driver instanceof JavascriptExecutor) {((JavascriptExecutor) driver).executeScript("arguments[0].style.border='2px solid red'", elem);}

The previous lines will draw a 2px red rectangle around the object with that XPATH in the screen.

Done!
Share this helpful trick with your friends!

No hay comentarios.:

Publicar un comentario