Selenium WebDriver wait till element is displayed

后端 未结 9 789
死守一世寂寞
死守一世寂寞 2020-11-29 04:14

I have searched on Google and the SO site and I get answers for JAVA but do not seem to get answers for node.js

I have a web app that takes time to load. I would like

9条回答
  •  庸人自扰
    2020-11-29 04:39

    Try something like this:

    function isItThere(driver, element){
    
        driver.findElement(webdriver.By.id(element)).then(function(webElement) {
                console.log(element + ' exists');
            }, function(err) {
                if (err.state && err.state === 'no such element') {
                    console.log(element + ' not found');
                } else {
                    webdriver.promise.rejected(err);
                }
            });
    }
    

    I adapted it slightly based on what I found here: Check if element exists - selenium / javascript / node-js and it worked a charm.

提交回复
热议问题