Gongas
Gongas

Reputation: 61

Selenium Wait does it wait the delay or ignores it if it finds it faster?

Hello guys I have a simple question, for instance im using this code:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".test-name")))
print("ELEMENT FOUND")

Does it wait explicitly 20 seconds, or does it wait only until it finds the element and waits a maximum of 20 seconds if not found?

Upvotes: 1

Views: 368

Answers (2)

0m3r
0m3r

Reputation: 12499

It wait only until it finds the element and waits a maximum of 20 seconds if not found

Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others.

WebDriverWait

This waits up to 20 seconds before throwing a TimeoutException unless it finds the element to return within 20 seconds. WebDriverWait by default calls the ExpectedCondition every 500 milliseconds until it returns successfully. A successful return is for ExpectedCondition type is Boolean return true or not null return value for all other ExpectedCondition types.

Explicit Waits

Upvotes: 1

0buz
0buz

Reputation: 3503

Check out the example and documentation here.

Quoting: "This waits up to 10 seconds before throwing a TimeoutException unless it finds the element to return within 10 seconds."

Upvotes: 1

Related Questions