Highlight elements in WebDriver during runtime

后端 未结 10 1223
离开以前
离开以前 2020-12-02 15:54

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

10条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 16:35

    I use below code for highlighting in my webdriver java code using javascript executer:

    //I make a call below function "flash"

        public static void flash(WebElement element, WebDriver driver) {
            JavascriptExecutor js = ((JavascriptExecutor) driver);
            String bgcolor  = element.getCssValue("backgroundColor");
            for (int i = 0; i <  3; i++) {
                changeColor("rgb(0,200,0)", element, js);
                changeColor(bgcolor, element, js);
            }
        }
        public static void changeColor(String color, WebElement element,  JavascriptExecutor js) {
            js.executeScript("arguments[0].style.backgroundColor = '"+color+"'",  element);
    
            try {
                Thread.sleep(20);
            }  catch (InterruptedException e) {
            }
         }
    

    Hope that helped :)

提交回复
热议问题