python - 预期条件间歇性失败并出现错误:TypeError: find_element() 采用 1 到 2 个位置参数,但给出了 3 个
问题描述
我在 Selenium 上遇到了这个奇怪的问题,正在寻求一些帮助。我正在使用预期条件来验证元素的存在。
问题是有时它运行良好,但有时会引发以下错误:
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_to_be_clickable()”的调用是正确的。我正在传递一个元组。我认为这是我的 xpath 或其他东西的长度,但这并没有导致任何地方。我在 expected_conditions.py 中添加了一些跟踪,以验证我是否传递了正确的参数。
调用预期条件
element = EC.element_to_be_clickable((By.XPATH, element_xpath))
WebDriverWait(self.driver, 10).until(element)
来自 expected_conditions.py 的输出
这有效:
在_find_element里面
by = ('xpath', "//span[contains(text(), 'SERVICES')]/../../..")
这些不会:
在_find_element里面
by = ('xpath', "//div[text() = 'STORAGE']/../div[2]/div[contains(@class, 'ls-add-icon ')]")
在_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 ')]")
关于我做错了什么的任何建议都会很可爱
解决方案
推荐阅读
- r - 如何排除存在“分离”一组点的线
- python - 如何让用户输入仅等于 1-8?
- protractor - 使用 Type Script 和 VS Code 调试量角器时浏览器不同步
- java - rxjava2 用于 onComplete 事件导致的负载测试不一致
- go - 通过反射将“interface {}”类型转换为“interface {}”类型切片中的另一个接口
- django - 有没有办法在 Heroku 中使用 python 模型“webbrowser”?
- c - 如何从C中的字符数组中获取数字
- wpf - WPF MVVM:从值变化触发行进点动画
- r - 将两个不属于数据框的变量传递给 R 中的 facet_grid()
- python - 浮点数在python末尾带有前导零