Why getting error AttributeError: 'WebDriver' object has no attribute 'executes_script'
获取self.driver.executes行的错误self.driver.executes_script("arguments[0].click();",new_notification)attributeError:"webdriver"对象没有"executes"属性没有但是它们是一个类名
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | import unittest from selenium import webdriver from selenium.webdriver.common.keys import Keys import HtmlTestRunner import time class Environment(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome(executable_path="F:\\automation\\chromedriver.exe") # login test case def test_first_page_login(self): driver = self.driver driver.maximize_window() driver.get("http://localhost/dashboard/user/login") self.driver.find_element_by_id('uemail').send_keys('[email protected]') self.driver.find_element_by_id('upwd').send_keys('1234567890') self.driver.find_element_by_id('upwd').send_keys(Keys.RETURN) # login page going def test_going_notification_page(self): self.test_first_page_login() time.sleep(5) going_noti_page = self.driver.find_element_by_class_name('caret') print(self.driver.execute_script("arguments[0].click();", going_noti_page)) new_notification = self.driver.find_element_by_class_name('fa-paper-plane') self.driver.executes_script("arguments[0].click();", new_notification) time.sleep(5) def tearDown(self): self.driver.quit() if __name__ =="__main__": unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='F:\\automation\ eports')) |
你只是有一个打字错误:
1 | self.driver.executes_script("arguments[0].click();", new_notification) |
文档:webdriver.execute_script