Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Selenium Python WebDriverWait Parenthesis Question

user_val = WebDriverWait(browser, 30).until(EC.presence_of_element_located((By.ID, "username")))

Why does EC.presence_of_element_located require two sets of parenthesis? I didn’t see the need for two pair so I removed one of them and the code quite working — I just flew by it like it was a comment. I added them back and it started working again. Just curious as to why it would require two sets?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

user_val = WebDriverWait(browser, 30).until(EC.presence_of_element_located((By.ID, "username")))

EC.presence_of_element_located is a method that takes a single argument, which is a tuple representing the locating strategy and the locator value. In this case, it’s (By.ID, "username").

WebDriverWait(browser, 30).until(...) is a method that takes a single argument, which is the expected condition to wait for.
Here, you are passing EC.presence_of_element_located((By.ID, "username")) as the expected condition.

Therefore, the double parentheses are necessary to encapsulate the arguments for both the presence_of_element_located method and the until method.

If you remove one set of parentheses, you are essentially passing the method itself (EC.presence_of_element_located) rather than calling it with the specified arguments, which leads to incorrect behavior.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading