在函数调用中指定 webdriver 定位器
specifying a webdriver locator in a function call
我正在寻找有关如何等待特定页面元素可点击的建议,并找到了这个 post:
post 中给出的代码是:
def _wait_and_click(self, locator, timeout):
try:
wait = WebDriverWait(self.driver, timeout)
wait.until(expected_conditions.element_to_be_clickable((locator["by"], locator["value"]))).click()
except TimeoutException:
return False
return True
这看起来和我需要的一模一样,但是我该如何称呼它呢?
我试过:
_wait_and_click(自我, (By.ID, 'next-button'), 60)
并出现以下错误:
Traceback (most recent call last):
File "testProject.py", line 65, in test002_new_project
_wait_and_click(self, (By.ID,'next-button'), 60)
File "testProject.py", line 23, in _wait_and_click
wait.until(expected_conditions.element_to_be_clickable((locator["by"], locator["value"]))).click()
TypeError: tuple indices must be integers, not str
那么我应该如何调用该函数?
您使用了 tuple() 而不是 dict()
_wait_and_click({'by': By.ID, 'value': 'next-button'}, 60)
我正在寻找有关如何等待特定页面元素可点击的建议,并找到了这个 post:
post 中给出的代码是:
def _wait_and_click(self, locator, timeout):
try:
wait = WebDriverWait(self.driver, timeout)
wait.until(expected_conditions.element_to_be_clickable((locator["by"], locator["value"]))).click()
except TimeoutException:
return False
return True
这看起来和我需要的一模一样,但是我该如何称呼它呢? 我试过: _wait_and_click(自我, (By.ID, 'next-button'), 60)
并出现以下错误:
Traceback (most recent call last):
File "testProject.py", line 65, in test002_new_project
_wait_and_click(self, (By.ID,'next-button'), 60)
File "testProject.py", line 23, in _wait_and_click
wait.until(expected_conditions.element_to_be_clickable((locator["by"], locator["value"]))).click()
TypeError: tuple indices must be integers, not str
那么我应该如何调用该函数?
您使用了 tuple() 而不是 dict()
_wait_and_click({'by': By.ID, 'value': 'next-button'}, 60)