PyCharm中运行firefox webdriver访问邮箱添加通讯录的时候报错-WebDriverException: Message: can't access dead object

调了半天,发现是因为在登录操作后没有从frame中切换出来导致的,因为在登录的时候需要先切换到frame中,登录之后要切换出来才能继续其他操作。

下面是我运行的代码,driver.switch_to.default_content()这一行被我注释掉了,结果就报这个错

代码:
driver=webdriver.Firefox(executable_path='c:\\geckodriver')
driver.get('http://mail.126.com')
try:
    wait=WebDriverWait(driver,10,0.2)#显示等待
    driver.switch_to.frame(driver.find_element_by_xpath("//iframe[@id='x-URS-iframe']"))#切换到用户名和密码输入框所在的frame元素

name=wait.until(lambda x:x.find_element_by_xpath("//input[@placeholder='邮箱帐号或手机号' and @name='email']"))
    name.send_keys('xiaxiaoxu1987')
    password=wait.until(lambda x:x.find_element_by_xpath("//input[@placeholder='密码']"))
    password.send_keys('gloryroad')
    submit=wait.until(lambda x:x.find_element_by_xpath("//a[@id='dologin']"))
    submit.click()
    #driver.switch_to.default_content()#在pycharm里用switch_to_default_content()会被加删除线,out了

address_book_link=wait.until(lambda x:x.find_element_by_xpath("//div[text()='通讯录']"))
    address_book_link.click()

运行报错:

C:\Python27\python.exe D:/test/dataDrivenTestPractice1/PageObject/test.py
Traceback (most recent call last):
  File "D:/test/dataDrivenTestPractice1/PageObject/test.py", line 27, in <module>
    address_book_link=wait.until(lambda x:x.find_element_by_xpath("//div[text()='通讯录']"))
  File "C:\Python27\lib\site-packages\selenium\webdriver\support\wait.py", line 71, in until
    value = method(self._driver)
  File "D:/test/dataDrivenTestPractice1/PageObject/test.py", line 27, in <lambda>
    address_book_link=wait.until(lambda x:x.find_element_by_xpath("//div[text()='通讯录']"))
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 387, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 957, in find_element
    'value': value})['value']
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 314, in execute
None
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
WebDriverException: Message: can't access dead object

Process finished with exit code 0

把注释去掉:

driver=webdriver.Firefox(executable_path='c:\\geckodriver')
driver.get('http://mail.126.com')
try:
    wait=WebDriverWait(driver,10,0.2)#显示等待
    driver.switch_to.frame(driver.find_element_by_xpath("//iframe[@id='x-URS-iframe']"))#切换到用户名和密码输入框所在的frame元素

name=wait.until(lambda x:x.find_element_by_xpath("//input[@placeholder='邮箱帐号或手机号' and @name='email']"))
    name.send_keys('xiaxiaoxu1987')
    password=wait.until(lambda x:x.find_element_by_xpath("//input[@placeholder='密码']"))
    password.send_keys('gloryroad')
    submit=wait.until(lambda x:x.find_element_by_xpath("//a[@id='dologin']"))
    submit.click()
    driver.switch_to.default_content()#在pycharm里用switch_to_default_content()会被加删除线,out了

address_book_link=wait.until(lambda x:x.find_element_by_xpath("//div[text()='通讯录']"))
    address_book_link.click()

结果:没有报错

C:\Python27\python.exe D:/test/dataDrivenTestPractice1/PageObject/test.py

Process finished with exit code 0

python webdriver 报错WebDriverException: Message: can't access dead object的原因(pycharm中)的更多相关文章

  1. python+appium 【已解决】真机运行appium报错“WebDriverException: Message: A new session could not be created. (Original error: Command failed: C:\Windows\system32\cmd.exe /s /c.......详见内文

    问题报错提示: selenium.common.exceptions.WebDriverException: Message: A new session could not be created. ...

  2. 关于执行webdriver.Chrome; 报错WebDriverException: Message: unknown error: Element is not clickable at point (1085, 103)

    from selenium import webdriverfrom time import sleep dr = webdriver.Chrome() dr.get("http://pj1 ...

  3. appium---【已解决】【Mac】from appium import webdriver报错提示“Unresolved import webdriver”

    报错提示: from appium import webdriver提示Unresolved import webdriver 报错原因:没有安装Appium_Python_Client 解决办法: ...

  4. mac 上python编译报错No module named MySQLdb

    mac 上python编译报错No module named MySQLdb You installed python You did brew install mysql You did expor ...

  5. from appium import webdriver 报错

    from appium import webdriver 报错 看看你的文件是不是就叫appium

  6. 调用python脚本报错/usr/bin/env: python : No such file or directory

    一.调用python脚本报错 /usr/bin/env: python: No such file or directory 二.解决方法 原因是在windows上编写的脚本,使用dos2unix对脚 ...

  7. java调用sqlldr报错:Message 2100 not found

    java调用Oracle的sqlldr命令报错:Message 2100 not found; No message file for product=RDBMS, facility=ULMessag ...

  8. 第一次打开pycharm运行python文件报错”No Python interpreter selected“问题的解决办法

    前面没有细讲,这里细述一下安装pycharm后,第一次打开pycharm运行python文件报错"No Python interpreter selected"问题的解决办法. 出 ...

  9. 【Mac 10.13.0】安装 libimobiledevice,提示报错:warning: unable to access '/Users/lucky/.config/git/attributes': Permission denied解决方案

    打开终端,执行命令: 1.sudo chown -R XXX /usr/local  (XXX表示当前用户名) 2.ruby -e "$(curl -fsSL https://raw.git ...

随机推荐

  1. NUC970 U-Boot 使用說明

    U-Boot 使用說明U-Boot 是一個主要用於嵌入式系統的開機載入程式, 可以支援多種不同的計算機系統結構, 包括ARM.MIPS.x86與 68K. 這也是一套在GNU通用公共許可證之下發布的自 ...

  2. checkbox多选框选择判断

    全选<input type="checkbox" name="select" id="select" value="chec ...

  3. php数据访问之查询关键字

    本文根据数据库中的car表做一个汽车查询页面,巩固php查询关键字操作,感兴趣的小伙伴们可以参考一下   本文实例为大家分享了php查询操作的实现代码,供大家参考,具体内容如下 一.一个关键字查询 主 ...

  4. 使用Sublime Text 3做Python开发

    引言 刚转到OS X平台时,寻找写Python,JavaScript,Markdown等文件的工具时,比较了许多工具, 最终选择了Sublime Text 2,主要原因是其跨平台, 想着以后再转到wi ...

  5. JavaWeb温习之HttpServletResponse对象

    以下内容均根据"方立勋JavaWeb视频教程"进行总结 1. HttpServletResponse常见应用——设置响应头控制浏览器的行为 1.1 设置http响应头控制浏览器禁止 ...

  6. 记一次开发:Qt简单电话本程序

    前言 断断续续学习C++一年了,现在要做课设,觉得控制台界面实在太难看,于是用Qt做一个图形化的程序出来. 学习Qt也没有多久,只是了解了个大概,这次开发基本上是啃了2天的官方帮助文档,然后利用各种Q ...

  7. Centos7 安装zabbix3.0 服务端 详细

    参考: https://www.cnblogs.com/37yan/p/6879218.html http://blog.csdn.net/hao134838/article/details/5712 ...

  8. ShowDoc 搭建 (未成功....)

    官方教程:https://www.showdoc.cc/help?page_id=13732 下载了showdoc,服务器映射本地磁盘的时候,服务器用户名和密码忘了... 远程服务器用户名和密码修改 ...

  9. 【BZOJ4922】[Lydsy六月月赛]Karp-de-Chant Number 贪心+动态规划

    [BZOJ4922][Lydsy六月月赛]Karp-de-Chant Number Description 卡常数被称为计算机算法竞赛之中最神奇的一类数字,主要特点集中于令人捉摸不透,有时候会让水平很 ...

  10. 【BZOJ1787】[Ahoi2008]Meet 紧急集合 LCA

    [BZOJ1787][Ahoi2008]Meet 紧急集合 Description Input Output Sample Input 6 4 1 2 2 3 2 4 4 5 5 6 4 5 6 6 ...