0
votes

Some elements may not exist in the page, but I have to wait 30 seconds, which makes me very distressed, because I have to find many elements that may not exist. Therefore, the problem of how to modify the default 30-second element that cannot be found has been bothering me.

Is this default wait time related to the selenium package?

WebDriverWait(driver,5).until(EC.presence_of_element_located((By.XPATH, '//input[@qtype="302"]')))

WebDriverWait(driver,5).until(EC.presence_of_all_elements_located((By.XPATH, '//input[@qtype="302"]')))

But they didn't meet my expectation of waiting ten seconds

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

driver = webdriver.Chrome()
driver.get(‘xxx')
driver.implicitly_wait(10)

try:
    start = perf_counter()
    dLfy_topic = WebDriverWait(driver,5).until(EC.presence_of_all_elements_located((By.XPATH, '//input[@qtype="302"]')))
except:
    during = perf_counter() - start
    print(during)
finally:
    if during > 10:
        print("You failed")
    else:
        print("You are successful")

30.53863444600001 You failed

I wish I had waited ten seconds instead of thirty!

1
What is 30.53863444600001 You failed exactly?DebanjanB

1 Answers

0
votes

There is no default 30 second wait built into selenium.

The behaviour you are describing would be caused by setting a 30 second implicit wait at some point in your code.

You can reset the implicit wait to default by calling

driver.implicitly_wait(0)

Generally using an implicit wait is an anti-pattern because of the problems you are currently seeing. I would suggest removing all implicit waits from your code and only using Explicit waits.

Also beware of mixing implicit and explicit waits. If you do this you are in the realms of undefined functionality and depending upon the driver binary and driver binding implementations you may get varied behaviour. The implicit wait may take precedence, or the explicit wait may take precedence giving you strange and varied wait times that don't always make sense.