解决selenium的WebDriver object has no attribute 'find_element_by_xpath’问题
在使用selenium操作浏览器时,常见的一种定位元素的方式就是Xpath定位。但有时候会出现WebDriver object has no attribute 'find_element_by_xpath’的错误提示,意思是WebDriver对象没有该方法。
这通常是因为引入selenium包时未正确命名WebDriver导致的。为了解决这个问题,只需要在导入selenium的时候明确地指定webdriver,代码如下:
from selenium import webdriver
browser = webdriver.Chrome()
elem = browser.find_element_by_xpath('xpath')
通过按照上述方式命名webdriver对象,即可避免WebDriver object has no attribute 'find_element_by_xpath’问题。
在使用selenium进行Xpath元素定位时遇到'WebDriver object has no attribute 'find_element_by_xpath''错误。该问题通常由于导入selenium时未正确命名WebDriver引起。解决方案是导入selenium时明确指定webdriver,修正后的代码可避免此类问题。
4万+

被折叠的 条评论
为什么被折叠?



