Selenium WebDriver wait till element is displayed

后端 未结 9 776
死守一世寂寞
死守一世寂寞 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:17

    Writing asynchronous function to avoid this problem

    (async function() {
      let url = args[0];
      await driver.get(url);
      driver.quit();
    })();
    
    0 讨论(0)
  • 2020-11-29 04:23

    I came up with this approach because it maintains the chainable promise syntax so that I can write this: await waitFind(By.id('abc')).click()

    const waitFind = (locator) => {
        return driver.findElement(async () => {
            await driver.wait(until.elementLocated(locator));
            return driver.findElement(locator);
        });
    }
    
    0 讨论(0)
  • 2020-11-29 04:24

    I stumbled upon an answer to my question

    So to wait for an element to appear we have to:

    driver.wait(function () {
        return driver.isElementPresent(webdriver.By.name("username"));
    }, timeout);
    
    0 讨论(0)
  • 2020-11-29 04:27

    I usually use this way:

     var el = driver.wait(until.elementLocated(By.name('username')));
    el.click();
    
    0 讨论(0)
  • 2020-11-29 04:28

    This is the only thing that is working for me:

    const element = By.id('element');
    driver.wait(until.elementLocated(element));
    const whatElement = driver.findElement(element);
    driver.wait(until.elementIsVisible(whatElement), 5000).click();
    
    0 讨论(0)
  • 2020-11-29 04:30

    You can register a listener on webdriver.wait by using then()

    return driver.wait(until.elementLocated(By.name('username')), 5 * 1000).then(el => {
        return el.sendKeys(username);
    });
    
    0 讨论(0)
提交回复
热议问题