解决selenium的WebDriver object has no attribute ‘find_element_by_xpath‘问题

解决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,python,测试工具)