Selenium webdriver explicit wait

后端 未结 7 1453
无人共我
无人共我 2021-01-03 10:21

I\'m writing some automated tests for using the selenium chrome driver. I trying to write a reusable method that will explicitly wait for elements to appear and then call th

7条回答
  •  孤城傲影
    2021-01-03 10:56

    Your problem is that you passed String to method parameter:

    public String waitForElement(String item) {

    You have to pass your WebElement, something like:

    public boolean visibilityOfElementWait(WebElement webElement) {
        if (webElement != null) {
            try {
                WebDriverWait wait = new WebDriverWait(Driver.getCurrentDriver(), 20);
                wait.until(ExpectedConditions.visibilityOf(wrappedElement));
                highlightElement(webElement);
                return true;
            } catch (Exception e) {
                return false;
            }
        } else
            Logger.logError("PageElement " + webElement.getText() + " not exist");
        return false;
    }
    
    public void highlightElement(WebElement element) {
        if (!Config.getProperty(Config.BROWSER).equalsIgnoreCase("ANDROIDHYBRID")) {
    
            String bg = element.getCssValue("backgroundColor");
    
            for (int i = 0; i < 4; i++) {
                Driver.getDefault()
                        .executeScript("arguments[0].style.backgroundColor = 'red'", element);
                Driver.getDefault()
                        .executeScript("arguments[0].style.backgroundColor = '" + bg + "'", element);
            }
    
       //            String highlightElementScript = "arguments[0].style.backgroundColor = 'red';";
       //            Driver.getDefault().executeScript(highlightElementScript, element);
        }
    }
    

提交回复
热议问题