解决:运行时出现 module 'lib2to3.pgen2.driver' has no attribute 'find_element'问题

出现 module 'lib2to3.pgen2.driver' has no attribute 'find_element'的原因有很多,这里我只提供我运行时出现的错误情况,即解决办法。

原始代码:

WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.XPATH, '//*[starts-with(@id,"s_user_name_menu"]/div/a[4]'))).click()
self.driver.find_element_by_class_name('quit').click()

错误原因:

Traceback (most recent call last):

File "D:\python\p\lib\unittest\case.py", line 59, in testPartExecutor yield

File "D:\python\p\lib\unittest\case.py", line 615, in run testMethod()

File "D:\python\Testkuangjia\unittest\pandabus_unittest\pandabus_unittest\testcase\test_login_baidu.py", line 67, in test_loginBtn WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.action-bar button.c-button.c-button--blue"))).click()

File "D:\python\p\lib\site-packages\selenium\webdriver\support\wait.py", line 71, in until value = method(self._driver)

File "D:\python\p\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 297, in __call__ element = visibility_of_element_located(self.locator)(driver)

File "D:\python\p\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 128, in __call__ return _element_if_visible(_find_element(driver, self.locator))

File "D:\python\p\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 411, in _find_element return driver.find_element(*by)

AttributeError: module 'lib2to3.pgen2.driver' has no attribute 'find_element'

即该模块中没有find_element属性的定义,

错误的原因是因为所导入的包不是自己所需要的包,即更不需要导入lib2to3.pgen2包(模块)

修改后的代码:

WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.action-bar button.c-button.c-button--blue"))).click()
self.driver.find_element_by_class_name('quit').click()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值