预期条件间歇性失败,出现错误:TypeError:find\u element()接受1到2个位置参数,但给出了3个

2024-03-29 11:05:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个奇怪的问题与硒和正在寻找一点帮助。我正在使用预期条件来验证元素的存在。你知道吗

问题是,有时它运行良好,但有时会引发以下错误:

File "selenium_func_call.py", line 327, in is_element_clickable
  WebDriverWait(self.driver, 10).until(element)
File "python3.5/site-packages/selenium/webdriver/support/wait.py", line 71, in until
  value = method(self._driver)
File "python3.5/site-packages/selenium/webdriver/support/expected_conditions.py", line 318, in __call__
  element = visibility_of_element_located(self.locator)(driver)
File "python3.5/site-packages/selenium/webdriver/support/expected_conditions.py", line 139, in __call__
  return _element_if_visible(_find_element(driver, self.locator))
File "python3.5/site-packages/selenium/webdriver/support/expected_conditions.py", line 440, in _find_element
  return driver.find_element(*by)
TypeError: find_element() takes from 1 to 2 positional arguments but 3 were given

我对“element\u to\u be\u clickable()”的调用是正确的。我正在传递一个元组。 我想是xpath的长度或者别的什么,但这并不意味着什么。 我添加了一些预期的痕迹_条件.py验证我传递的参数是否正确。你知道吗

Call to Expected Conditions

element = EC.element_to_be_clickable((By.XPATH, element_xpath))
WebDriverWait(self.driver, 10).until(element)

预期的输出_条件.py你知道吗

这样做有效:

inside _find_element

by = ('xpath', "//span[contains(text(), 'SERVICES')]/../../..")

这些没有:

inside _find_element

by = ('xpath', "//div[text() = ' STORAGE']/../div[2]/div[contains(@class, 'ls-add-icon ')]")

inside _find_element

by = ('xpath', "//input[@name = 'id' and @value = 'Mint_Choco_Chip']/../../../../../div/div/div[text() = ' STORAGE']/../div[2]/div[contains(@class, 'ls-add-icon ')]")

任何关于我做错了什么的建议都是很好的


Tags: inpyselfdivsupportpackagesdriverselenium