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. VS2015编译TIFF3.8.0源码

    没有CMakeLists.txt,不能使用CMake GUI了.源文件中有makefile.vc,所以使用nmake 进入VS2015命令行 nmake -f makefile.vc 修改nmake. ...

  2. 《C++ Primer Plus》14.2 私有继承 学习笔记

    C++(除了成员变量之外)还有另一种实现has-a关系的途径——私有继承.使用私有继承,基类的公有成员和保护成员都将成为派生类的私有成员.(如果使用保护继承,基类的公有成员和保护成员都将称为派生类的保 ...

  3. 谷歌Volley网络框架讲解——网络枢纽

    研究了这么久的Volley,愈来愈发现这个框架的精美和人性化.比起民间一些框架强很多,一开始总是盲人摸象找不到头绪,现在终于有些明朗了.Volley其实就是一个请求队列的代理类,我们看下UML. 这就 ...

  4. AndroidのListView之滑动列表项(点击事件和滑动事件共存)

    这里正好在项目有这么一个bt的需求,如下图ListView的item可以响应点击事件也可以响应item的左右滑动事件,两个事件可以相互独立互不影响. 听说iphone的list选项就有这样bt的功能, ...

  5. codeforce 148D. Bag of mice[概率dp]

    D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  6. ntpdate自动对准时间的脚本

    author:headsen  chen date: 2018-10-09  19:50:15 #!/bin/bash yum -y install ntpdate /usr/sbin/ntpdate ...

  7. [Fine Uploader] 用Fine Uploader+ASP.NET MVC实现ajax文件上传[代码示例]

    Fine Uploader(http://fineuploader.com/)是一个实现 ajax 上传文件的 Javascript 组件   This project attempts to ach ...

  8. 获取鼠标经过位置的X、Y坐标

    利用JavaScript获取鼠标经过位置的X.Y坐标方法. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN& ...

  9. 利用Linux系统生成随机密码的8种方法

    Linux操作系统的一大优点是对于同样一件事情,你可以使用高达数百种方法来实现它.例如,你可以通过数十种方法来生成随机密码.本文将介绍生成随机密码的十种方法. 1. 使用SHA算法来加密日期,并输出结 ...

  10. Quartz学习记录

    参考资料: 官方网站 Quartz使用总结