Python Selenium WebDriverWait on many loaded but nonclickable elements until one becomes clickable

Viewed 28

I'm automating the click action on a terribly innovatively written website.
There are three button/clickable elements, all of them are loaded and have presence_of_element_located == True
Only one will have element_to_be_clickable == True
I want to use WebDriverWait to wait on a single CSS selector "a, b, c"(so I can reuse the same code with other sites) until one of the buttons becomes clickable

DOM example of three buttons notes the one without style="display: none; might change:
<button[class='AddCart1'] style="display: none;">
<button[class='AddCart2']>
<button[class='AddCart3']style="display: none;">

My code:
def wait_until_clickable(wd: webdriver, item_selector: str, timeout: int) -> None:
WebDriverWait(wd, time_out).until(EC.element_to_be_clickable((By.CSS_SELECTOR, item_selector)))

Resutls:

  1. If the clickable element is the first in DOM, the WebDriverWait until returns the proper element
  2. If the clickable element is not the first in DOM, TimeoutException is thrown

What I am expecting:

Regardless how a, b , c are ordered in DOM, the above code should always return the clickable element after the wait

From what I read, adding , in CSS_SELECTOR should act as an OR operator, but it doesn't seem to be the case here. Could someone help me to figure out how to do this properly?

The website is publicly accessible https://www.amiami.com/eng/. The button for pre-ordering and the button for adding in-stock items to cart are different (there exists a thrid btn-cart button but I have yet to figure out where it is used). Additionally, both buttons are always in DOM regardless of the status of the item (pre-order, available now, or out of stock), style="display: none; is used to control what content is displayed.

0 Answers
Related