【Python】selenium调用IE11浏览器,报错“找不到元素”NoSuchWindowException: Message:Unable to find element on closed window
2017-05-24 10:37
916 查看
当编写自动化脚本,定位浏览器元素时,报如下错误:
代码:
报错:
解决方法:
For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates. (这段告诉你需要修改注册表。)
For 32-bit Windows installations, the key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. (32bit Windows看这里。)
For 64-bit Windows installations, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.(64bit Windows看这里。)
翻译过来的意思即,修改你的注册表(Run->regedit->Enter),路径如下:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
如果FeatureControl下没有FEATURE_BFCACHE,就以FEATURE_BFCACHE为名new一个key!并在其下创建一个DWORD,取名为:iexplore.exe,value为0。
修改完你的注册表后,重启你的计算机。
【参照】:http://blog.csdn.net/angel_xiaa/article/details/52212340
但是发现我再定位元素时候还是报错,我就怀疑是不是Selenium版本问题,因为我安装的是Selenium3.X的版本,然后我运行cmd把3.X卸载重新安装2.X版本就好了。
卸载命令:pip uninstall selenium //卸载当前安装的包
安装命令:pip install selenium==2.48.0 //指定版本号安装
查看命令:pip show selenium //查看当前包的版本信息
代码:
>>> # coding=utf-8 >>> from selenium import webdriver >>> driver = webdriver.Ie() >>> driver.get("www.baidu.com") >>> driver.find_element_by_id("kw").send_keys("Selenium2")
报错:
解决方法:
For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates. (这段告诉你需要修改注册表。)
For 32-bit Windows installations, the key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. (32bit Windows看这里。)
For 64-bit Windows installations, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE. Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.(64bit Windows看这里。)
翻译过来的意思即,修改你的注册表(Run->regedit->Enter),路径如下:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
如果FeatureControl下没有FEATURE_BFCACHE,就以FEATURE_BFCACHE为名new一个key!并在其下创建一个DWORD,取名为:iexplore.exe,value为0。
修改完你的注册表后,重启你的计算机。
【参照】:http://blog.csdn.net/angel_xiaa/article/details/52212340
但是发现我再定位元素时候还是报错,我就怀疑是不是Selenium版本问题,因为我安装的是Selenium3.X的版本,然后我运行cmd把3.X卸载重新安装2.X版本就好了。
卸载命令:pip uninstall selenium //卸载当前安装的包
安装命令:pip install selenium==2.48.0 //指定版本号安装
查看命令:pip show selenium //查看当前包的版本信息
相关文章推荐
- NoSuchWindowException:Unable to find element (on closed window)/(with xpath)
- fix org.openqa.selenium.NoSuchWindowException when find element on windows8.1 ie11.
- iframe,switchToWindow报错--no such element: Unable to locate element
- Appium 报错:org.openqa.selenium.NoSuchWindowException: no such window: target window already closed
- Python+Selenium定位不到元素常见原因及解决办法(报:NoSuchElementException)
- org.openqa.selenium.NoSuchElementException: Unable to locate element: 异常解决方法
- [转]org.openqa.selenium.NoSuchElementException: Unable to locate element: 异常解决方法
- Python+Selenium定位不到元素常见原因及解决办法(报:NoSuchElementException)
- no such element: Unable to locate element--窗口切换
- mac下安装mysql-python包报unable to execute llvm-gcc-4.2: No such file or directory error: command 'llvm-g
- [selenium&Python] find_element_by_name找不到element
- 解决Selenium弹出新页面无法定位元素问题(Unable to locate element)
- Python中在跳转页面时,在新的页面就不能定位到元素了Unable to locate element
- python+selenium unable to locate element
- NoSuchElementException: Unable to locate element--三种系统等待时间
- Selenium2+python自动化44-元素定位参数化(find_element)
- Selenium2+python自动化-元素定位参数化(find_element)
- selenium调用IE11浏览器,报错“找不到元素”