python webdriver 报错WebDriverException: Message: can't access dead object的原因(pycharm中)
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中)的更多相关文章
- 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. ...
- 关于执行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 ...
- appium---【已解决】【Mac】from appium import webdriver报错提示“Unresolved import webdriver”
报错提示: from appium import webdriver提示Unresolved import webdriver 报错原因:没有安装Appium_Python_Client 解决办法: ...
- mac 上python编译报错No module named MySQLdb
mac 上python编译报错No module named MySQLdb You installed python You did brew install mysql You did expor ...
- from appium import webdriver 报错
from appium import webdriver 报错 看看你的文件是不是就叫appium
- 调用python脚本报错/usr/bin/env: python : No such file or directory
一.调用python脚本报错 /usr/bin/env: python: No such file or directory 二.解决方法 原因是在windows上编写的脚本,使用dos2unix对脚 ...
- java调用sqlldr报错:Message 2100 not found
java调用Oracle的sqlldr命令报错:Message 2100 not found; No message file for product=RDBMS, facility=ULMessag ...
- 第一次打开pycharm运行python文件报错”No Python interpreter selected“问题的解决办法
前面没有细讲,这里细述一下安装pycharm后,第一次打开pycharm运行python文件报错"No Python interpreter selected"问题的解决办法. 出 ...
- 【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 ...
随机推荐
- brocadcastReceiver
用来接收广播, 可以根据系统发生的一些时间做出一些处理 系统的一些事件,比如来电,来短信,等等,会发广播:可监听这些广播,并进行一些处理: Android3.2以后,为了安全起见,对于刚安装的应用,需 ...
- M0 M4之Timer初始化
新唐的定时器一般有很多功能:普通的定时功能,事件计数功能,捕获功能,超时触发ADC等等.大家如果感兴趣可以读一下<NANOB Timer功能介绍以及在弱灌注中的应用.pdf>,虽然各个系列 ...
- LeetCode——Move Zeroes
Description: Given an array nums, write a function to move all 0's to the end of it while maintainin ...
- hdu1024 Max Sum Plus Plus[降维优化好题(貌似以后可以不用单调队列了)]
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Android - 获取SD卡的内存空间大小
获取SD卡的内存空间大小 //获得SD卡空间的信息 File path=Environment.getExternalStorageDirectory(); StatFs statFs=new Sta ...
- [Gradle] 输出构建 APK 的版本名到文件
android { // 输出版本名到 build 目录下的 version_name.txt 文件 applicationVariants.all { variant -> project.t ...
- python使用MySqlDB
下载安装MySQLdb <1>linux版本 http://sourceforge.net/projects/mysql-python/ 下载,在安装是要先安装setuptools,然后在 ...
- 南京网络赛B-The writing on the wall
30.43% 2000ms 262144K Feeling hungry, a cute hamster decides to order some take-away food (like frie ...
- try...finally的妙用
受博文 C#中Finally的一个不太常见的用法 的启发,正好在开发中遇到这样一段代码: public bool ChangeBlogApp(Guid userID, string oldBlogAp ...
- ubuntu下完全卸载opencv3.1.0
在ubuntu下删除opencv需要以下步骤: 1.进入opencv的源代码文件夹下的release(这是你在安装opencv时候自己命名的,cmake时候所在的目录) 2.执行以下命令 sudo m ...