【Selenium】【BugList8】126邮箱定位不到“退出”按钮:Message: TypeError: can't access dead object

【流程描述】

登录126邮箱,退出

 

【代码】

#coding=utf-8
from selenium import webdriver

driver = webdriver.Firefox()
#driver = webdriver.Ie()
driver.implicitly_wait(10)
driver.get("https://mail.126.com/")

#切换到frame
driver.switch_to.frame("x-URS-iframe")
#输入密码、用户名,登录

driver.find_element_by_name("password").clear()
driver.find_element_by_name("password").send_keys("xxx")
driver.find_element_by_name("email").clear()
driver.find_element_by_name("email").send_keys("yyy")

driver.find_element_by_id("dologin").click()

#退出
driver.find_element_by_xpath("/html/body/header/div[1]/ul[1]/li[16]/a").click()
driver.quit()

 

【报错】

====================== RESTART: F:/PySouce/mail1261.py ======================
Traceback (most recent call last):
File "F:/PySouce/mail1261.py", line 26, in <module>
driver.find_element_by_xpath("/html/body/header/div[1]/ul[1]/li[16]/a").click()
File "D:\Program Files\python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 385, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "D:\Program Files\python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 955, in find_element
'value': value})['value']
File "D:\Program Files\python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "D:\Program Files\python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: TypeError: can't access dead object

 

【解决方法】

#coding=utf-8
from selenium import webdriver

driver = webdriver.Firefox()
#driver = webdriver.Ie()
driver.implicitly_wait(10)
driver.get("https://mail.126.com/")

#切换到frame
driver.switch_to.frame("x-URS-iframe")
#输入密码、用户名,登录

driver.find_element_by_name("password").clear()
driver.find_element_by_name("password").send_keys("xxx")
driver.find_element_by_name("email").clear()
driver.find_element_by_name("email").send_keys("yyy")

driver.find_element_by_id("dologin").click()

#切换到主文档
driver.switch_to.default_content()
driver.implicitly_wait(10)
#退出
driver.find_element_by_xpath("/html/body/header/div[1]/ul[1]/li[16]/a").click()
driver.quit()

 

 

【Ending】

微信公众号“粒粒的测试笔记

  

posted @ 2018-09-03 17:22  粒粒的测试笔记  阅读(560)  评论(2编辑  收藏  举报