Highlight elements in WebDriver during runtime

后端 未结 10 1196
离开以前
离开以前 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条回答
  •  Happy的楠姐
    2020-12-02 16:45

    JavaScript : Find Xpath of an element and Draw Border around it,

    using styleObj.setProperty(CSS propertyName, CSS propertyValue, priority) method. element_node.style.setProperty ("background-color", "green", null);

    test js-code on this site : https://developer.chrome.com/devtools/docs/console

    var xpath = '//html/body/div/main/article/nav';
    if (document.evaluate){
    var element_node = document.evaluate(xpath, window.document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue;
    element_node.style.setProperty ('border', '3px solid green', 'important');
    
    alert('Working Fine in this browser version');
    }else{
    alert('document.evaluate is Not supported by Internet Explorer');
    }
    

    Selenium

    public static void drawBorder(WebDriver driver, String xpath){
            WebElement element_node = driver.findElement(By.xpath(xpath));
            JavascriptExecutor jse = (JavascriptExecutor) driver;
            jse.executeScript("arguments[0].style.border='3px solid red'", element_node);
        }
    

提交回复
热议问题