0

Based on every answer and piece of documentation I've seen, the following should wait for the element at xpath path:

delay = some amount of time way longer than I know is needed
driver = webdriver.Firefox()
driver.get(url)
wait = WebDriverWait(driver, delay, ignored_exceptions=NoSuchElementException)
wait.until(EC.presence_of_element_located(driver.find_element_by_xpath(path)))

but no matter what I do it always throws a NoSuchElementException immediately after getting the url. And before anyone marks this as a duplicate or calls me out on it, I am aware of this answer and although the element I'm looking for is in some kind of wrapper, I got the same problem when trying the above looking for that wrapper instead (also it works if I just provide a normal sleep call instead of the Expected Condition stuff which makes me think I don't need to manually enter into the wrapper). What's the point of having a function for waiting for an element to be loaded that doesn't wait until the element is loaded? Any help in solving this problem would be greatly appreciated.

Community
  • 1
  • 1

1 Answers1

-1

I use this java code for similar situations:

private Wait<WebDriver> staleWait = new FluentWait<>(getDriver())
        .withTimeout(WAIT_INTERVAL, TimeUnit.SECONDS)
        .pollingEvery(POLLING_INTERVAL, TimeUnit.MILLISECONDS)
        .ignoring(NoSuchElementException.class)
        .ignoring(StaleElementReferenceException.class);


protected WebElement visibilityOf(WebElement webElement) {
    staleWait.until((ExpectedCondition<Boolean>) webDriver -> {
        try {
            return element(webElement).isDisplayed();
        } catch (StaleElementReferenceException e) {
            return false;
        } catch (NoSuchElementException ne) {
            return false;
        }
    });

    return element(webElement);
}
nemelianov
  • 911
  • 1
  • 7
  • 15