present_of_element_located:“ str”对象没有属性“ w3c”

时间:2019-07-25 15:38:32

标签: python selenium-webdriver

Selenium / Python:我正在尝试使用WebDriverWait通过xpath定位元素。我确定我缺少一些简单的东西,并且相同的基本要素正在代码的其他部分起作用。我进入Java领域已经有一段时间了,正在重新适应python。

它引发错误:

File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 964, in find_element
   if self.w3c:  
AttributeError: 'str' object has no attribute 'w3c'

我已经尝试过在present_of_element_located的参数中使用不带括号的

出于说明目的,xpath已更改为“ // *”,但即使使用此xpath,错误仍然相同。

return WebDriverWait(self.driver, timeout, 0.5).until(EC.presence_of_element_located((By.XPATH, "//*")))

1 个答案:

答案 0 :(得分:0)

我在使用“预期条件”时遇到了很多问题,并且遇到间歇性错误。

我通过以下方式调用了WebDriverWait,它可以在我的环境/用例中工作。

WebDriverWait(self.driver, 10).until(lambda x: x.find_element_by_xpath(element_xpath).is_displayed())

希望这会有所帮助!