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. cocos2d-x游戏引擎核心之三——主循环和定时器

    一.游戏主循环 在介绍游戏基本概念的时候,我们曾介绍了场景.层.精灵等游戏元素,但我们却故意避开了另一个同样重要的概念,那就是游戏主循环,这是因为 Cocos2d 已经为我们隐藏了游戏主循环的实现.读 ...

  2. InstallShield程序打包图解

    InstallShield程序打包图解     VS2012中打包工具被看做程序集,在使用时和程序集一样被创建到程序解决方案下.需要我们做的是添加项目即可.但是对于初次使用的朋友来说,我们需要根据提示 ...

  3. Synergy 多系统共享鼠标键盘 Windows 和 Mac 完全配置教程

    公司终于配上了双主机双系统双屏幕,编码是爽了,但是桌上的键盘有多了一套,有没有什么软件能够在不同的电脑之间共享键盘和鼠标呢?后来发下了Synergy这款软件.不仅免费而且开源(支持下). 让办公桌上的 ...

  4. Deploying Cloud Foundry on OpenStack Juno and XenServer (Part II)

    link http://rabbitstack.github.io/deploying-cloud-foundry-on-openstack-juno-and-xenserver-part-ii/ L ...

  5. LeetCode - Delete Duplicate Emails

    Discription:Write a SQL query to delete all duplicate email entries in a table named Person, keeping ...

  6. hql 语法与详细解释<转>

    HQL查询 HQL查询: Criteria查询对查询条件进行了面向对象封装,符合编程人员的思维方式,不过HQL(Hibernate Query Lanaguage)查询提供了更加丰富的和灵活的查询特性 ...

  7. PHP内存缓存功能memcached

    PHP内存缓存功能memcached: http://blog.csdn.net/fangaoxin/article/details/6223383

  8. MACOS配置VIM成简单IDE傻瓜式操作

    零.参考文献: https://www.jianshu.com/p/f0513d18742a 一.安照我的配置:保存文件 " Configuration file for vim " ...

  9. MySQL Server has gone away报错原因汇总分析(转自:http://cenalulu.github.io/mysql/mysql-has-gone-away/)

    原因1. MySQL 服务宕了 判断是否属于这个原因的方法很简单,执行以下命令,查看mysql的运行时长 $ mysql -uroot -p -e "show global status l ...

  10. windows本地环境如何用wamp配置多域名绑定访问

    https://jingyan.baidu.com/article/acf728fd5fcdadf8e510a3e5.html