提问:命名获取到了loc的值,为啥说空类型对象没有find_element属性?应该怎么写呢
class Base:
def __init__(self,driver):
self.driver = driver
#定位元素方法 封装
def base_find(self,loc,timeout=30,poll=0.5):
# 使用显示等待 查找元素
print(loc)
return WebDriverWait(self.driver,timeout=timeout,
poll_frequency=poll).until(lambda x:x.find_element(*loc))
运行结果:
C:\Users\lihao\AppData\Local\Programs\Python\Python36\python.exe "D:\Pycharm\PyCharm 2018.3.3\helpers\pycharm\_jb_unittest_runner.py" --target test01_login.TestLogin
Launching unittests with arguments python -m unittest test01_login.TestLogin in E:\PythonWork\自动化测试\WebUI\ShopXO商城项目实战\testcase
('partial link text', '登录')
Ran 0 tests in 13.137s
FAILED (errors=1)
Failure
Traceback (most recent call last):
File "C:\Users\lihao\AppData\Local\Programs\Python\Python36\lib\unittest\suite.py", line 163, in _handleClassSetUp
setUpClass()
File "E:\PythonWork\自动化测试\WebUI\ShopXO商城项目实战\testcase\test01_login.py", line 24, in setUpClass
cls.login.page_click_login_link()
File "E:\PythonWork\自动化测试\WebUI\ShopXO商城项目实战\Page\page_login.py", line 8, in page_click_login_link
self.base_click(Page.login_link)
File "E:\PythonWork\自动化测试\WebUI\ShopXO商城项目实战\Base\base.py", line 18, in base_click
self.base_find(loc).click()
File "E:\PythonWork\自动化测试\WebUI\ShopXO商城项目实战\Base\base.py", line 15, in base_find
poll_frequency=poll).until(lambda x:x.find_element(*loc))
File "C:\Users\lihao\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\support\wait.py", line 71, in until
value = method(self._driver)
File "E:\PythonWork\自动化测试\WebUI\ShopXO商城项目实战\Base\base.py", line 15, in <lambda>
poll_frequency=poll).until(lambda x:x.find_element(*loc))
AttributeError: 'NoneType' object has no attribute 'find_element'
Process finished with exit code 1