Home > other >  Python Selenium How Can I Wait For Xpath Element
Python Selenium How Can I Wait For Xpath Element

Time:01-30

I want to wait for this xpath element until the xpath element I use below opens. How can I do it. Thank you in advance for your answers.

//div[@]/ul/li[3]

CodePudding user response:

The best approach to wait for elements with Selenium is to use Expected Conditions explicit waits.
With the following imports

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

And after initializing an instance of the wait object like the following

wait = WebDriverWait(driver, 20)

You will be able to wait until the element visibility with:

wait.until(EC.visibility_of_element_located((By.XPATH, '//div[@]/ul/li[3]')))

CodePudding user response:

We have multiple Waits in selenium but the best one is explicit.

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));

Now you will be able to apply wait according to your need, there is multiple expected conditions out there or you can customize it:

wait.until(ExpectedConditions.Condition(Locator));

Note: For details please visit Waits

  •  Tags:  
  • Related