环境:
win7 SP1 x_64
python3
selenium 3.14.0
IE 11
操作如下代码时会出现错误“selenium.common.exceptions.NoSuchWindowException: Message: Currently focused window has been closed.”
import time
from selenium import webdriver
def main():
url="http://xxxxxxxxxxxxx/xx/logon.jsp"
ie_path=r'E:\Python\project\IEDriverServer_x64_3.141.0.exe'
driver=webdriver.Ie(executable_path=ie_path)
driver.get(url)
time.sleep(2)
login_btn=driver.find_element_by_id("login_button")
login_btn.click()
driver.find_element_by_id("menuDiv10").click()
driver.quit()
在操作login_btn.clik()之前一直可以可以获取driver。
在执行driver.find_element_by_id("menuDiv10").click()时会出现错误“selenium.common.exceptions.NoSuchWindowException: Message: Currently focused window has been closed.”
一开始怀疑是iframe的问题,后来添加print(driver.title)报出unable to get browser的错误
经查询
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration
得知需要配置注册表(我的是64位的)
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
新建一个 DWORD 名字是 iexplore.exe 值是 0.
名称 | 类型 | 数据 |
---|---|---|
iexplore.exe | REG_DWORD | 0x00000000 (0) |
网友评论