2
votes

selenium: 3.141.0, Language: Python 3.

I am getting the following error while accessing the below explicit wait method.

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


driver = webdriver.Chrome(
    "Path\\ChromeDriver_32.exe")
driver.get('foo')

element = WebDriverWait(driver, 10).until(
    EC.staleness_of((By.XPATH, "//div[@class='loading_icon']")))

print(element)

Expected Results: Return True after element exited from DOM.

Actual Results: AttributeError: 'tuple' object has no attribute 'is_enabled'

Traceback (most recent call last):
  File "......../temp.py", line 14, in <module>
    EC.staleness_of((By.XPATH, "//div[@class='loading_icon']")))
  File "...\Python\Python37-32\lib\site-packages\selenium\webdriver\support\wait.py", line 71, in until
    value = method(self._driver)
  File "...\Python\Python37-32\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 315, in __call__
    self.element.is_enabled()
AttributeError: 'tuple' object has no attribute 'is_enabled'

Could someone help me what have I done wrong?

1

1 Answers

5
votes

You are passing in a tuple to a method that expects an element. From the expected_conditions.staleness_of() documentation:

class selenium.webdriver.support.expected_conditions.staleness_of(element)

Wait until an element is no longer attached to the DOM. element is the element to wait for.

This differs from some of the other expected_conditions convenience methods, which take a locator argument. This particular method can't take a locator, because a locator can only ever find elements that are still attached to the DOM.

Locate the element first before it has been detached:

from selenium.common.exceptions import NoSuchElementException

try:
    element = driver.find_element_by_xpath("//div[@class='loading_icon']")
    WebDriverWait(driver, 10).until(EC.staleness_of(element))
except NoSuchElementException:
    element = None