forked from Madusudanan/Selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebElementHighlighterAsEventListener.java
More file actions
29 lines (22 loc) · 1.09 KB
/
Copy pathWebElementHighlighterAsEventListener.java
File metadata and controls
29 lines (22 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* Code to highlight a web element in Selenium.Makes use of Javascript to highlight.
* This class implements the AbstractWebDriverEventListener.
* Create an Object of this class type and register it with a EventFiringWebDriver.
* Make sure you do all the web driver operations on the EventFiringWebDriver,so that the logging happens here.
* There are several other methods in the AbstractWebDriverEventListener.You can implement/use it if required
*/
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.events.AbstractWebDriverEventListener;
public class WebElementHighlighterAsEventListener extends AbstractWebDriverEventListener {
public void beforeFindBy(By arg0, WebElement arg1, WebDriver arg2) {
arg1 = arg2.findElement(arg0);
for (int i = 0; i < 1; i++) {
JavascriptExecutor js = (JavascriptExecutor) arg2;
js.executeScript(
"arguments[0].setAttribute('style', arguments[1]);", arg1,
"color: black; border: 3px solid black;");
}
}
}