我有一个带有属性 "aria-busy" 的元素,在搜索数据时会从 true 改变为 false。如何使用 selenium 中的“预期条件”和“显式等待”等待默认时间,例如 20 秒,如果 20 秒到了但属性未从 true 改变为 false,则抛出异常。我有以下代码,但它并不起作用。
import selenium.webdriver.support.ui as ui
from selenium.webdriver.support import expected_conditions as EC
<div id="xxx" role="combobox" aria-busy="false" /div>
class Ele:
def __init__(self, driver, locator)
self.wait = ui.WebDriverWait(driver, timeout=20)
def waitEle(self):
try:
e = self.driver.find_element_by_xpath('//div[@id='xxxx']')
self.wait.until(EC.element_selection_state_to_be((e.get_attribute('aria-busy'), 'true')))
expect:
raise Exception('wait timeout')