小编Avi*_*Das的帖子

如何修复 AttributeError:“NoneType”对象没有属性“click”

如何解决错误AttributeError: \'NoneType\' object has no attribute \'click\'?它的失败在于self.home.get_you_button().click(). 当我没有创建页面对象类时,它\xe2\x80\x99s 工作正常...它单击“You”按钮,没有任何错误,但通过使用 POM,它\xe2\x80\x99s 失败。网址是https://huew.co/

\n\n

代码试验:

\n\n
from selenium.webdriver.support import expected_conditions\nfrom selenium.webdriver.support.wait import WebDriverWait\n\nclass HomePage():\n\n    def __init__(self,driver):\n        self.driver = driver\n\n    def wait_for_home_page_to_load(self):\n        wait =WebDriverWait(self.driver,30)\n        wait.until(expected_conditions.visibility_of(self.driver.find_element_by_tag_name(\'html\')))\n\n    def get_you_button(self):\n\n        try:\n            element = self.driver.find_element_by_xpath("//div[@class=\'desktop-public-header\']/a[@ng-controller=\'UserNavigationInteractionCtrl\'][6]")\n\n        except:\n            return None\n
Run Code Online (Sandbox Code Playgroud)\n

python selenium python-3.x selenium-webdriver webdriverwait

2
推荐指数
1
解决办法
2万
查看次数