1

I was simply wondering when using Selenium for python why there are 2 parentheses in between the element_to_be_clickable and the By methods, such as:

WebDriverWait(browser, 50).until(
    EC.element_to_be_clickable((By.CSS_SELECTOR, "css_selector")))

This is also visble in the docs - http://selenium-python.readthedocs.io/waits.html

Any answers?

Cheers

5
  • Obviously, this is because element_to_be_clickable() should get iterable object as argument. If parenteses confusing you, you might use EC.element_to_be_clickable([By.CSS_SELECTOR, "css_selector"]) :)
    – Andersson
    Commented Feb 18, 2017 at 13:58
  • 1
    @Andersson what is "obvious" to one is not always obvious to another. That's one of the reasons this site exists.
    – JeffC
    Commented Feb 18, 2017 at 17:17
  • @JeffC, tuple is the very basics of python and I'm quite sure that there is more than enough information in web about what is it, how to use it and what for..
    – Andersson
    Commented Feb 18, 2017 at 20:26
  • @Andersson I don't disagree with you but when you are starting and you don't know what to call it, it's hard to search for.
    – JeffC
    Commented Feb 18, 2017 at 20:49
  • @Andersson The issue isn't about knowing tuples (which I know thanks) but locators in Selenium. And given that your comment slightly differs from the answer below, I still consider, even on second thought, that the question was legitimate :) Relax my friend Commented Feb 19, 2017 at 12:18

1 Answer 1

4

According to the API documentation the method element_to_be_clickable expects one argument: a locator. A locator is a tuple of (by, path).

So the inner pair of parentheses are for the tuple literal, while the outer parentheses are for bounding the function parameters (only one in this case).

2
  • Can I use a list instead of a tuple? Andersson's comment above suggests doing so but doesn't mention explicitly that a tuple (by, path) can be replaced with a list [by, path] as the locator argument for this method.
    – ADTC
    Commented Jun 15, 2022 at 15:56
  • This depends on the implementation in the API. The documentation says that the argument can be a locator (which "is a tuple of (by, path)"), a locator text, or a Web Element. It is likely it will also work with a list, but if the documentation speaks of tuple, better use tuple. If readability is the issue, you can also write EC.element_to_be_clickable(tuple([By.CSS_SELECTOR, "css_selector"]))
    – trincot
    Commented Jun 15, 2022 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.