【发布时间】:2017-07-25 23:38:13
【问题描述】:
我已经到处寻找答案,但找不到任何可以解决我的问题的方法。我正在尝试在 IE11 中运行我的 Selenium 测试。所有其他浏览器都可以正常工作(包括 Edge)。如下简单测试会导致问题...
System.setProperty("webdriver.ie.driver.loglevel","TRACE");
System.setProperty("webdriver.ie.driver.logfile", "C:/Projects/logme.txt");
driver = new InternetExplorerDriver();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.get("http:www.google.com");
driver.findElement(By.id("lst-ib")).click;
IE11 将启动并导航到 URL,但它无法在任何页面的任何位置找到任何元素。同样,我知道人们遇到了这个问题,但没有任何建议可以解决我的问题。这是我每次返回的错误:
org.openqa.selenium.NoSuchElementException: Unable to find element with id == lst-ib (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 3.23 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.2.0', revision: '8c03df6b79', time: '2017-02-23 10:51:31 +0000'System info: host: 'DESKTOP-63BRP93', ip: '10.0.110.68', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.ie.InternetExplorerDriverCapabilities [{browserAttachTimeout=0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:38992/, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss}]
Session ID: 0fbcebc8-6775-4a6c-b10a-47350502598f
*** Element info: {Using=id, value=lst-ib}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
这是我尝试/完成的...
- 将所有区域的启用保护模式设置为禁用
- 在高级选项卡或 IE 选项中设置允许脚本选项
- 尝试了人类已知的所有 IEDriver 功能,例如setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION,true);
- 试过 IE11 32 和 64 位
- 尝试通过类、标记名和所有其他定位器查找元素均无济于事。
- 为 32 位和 64 位 IE 实例添加了 2 个注册表项 BFCACHE
- 哭了很多
下面是附加的日志,我找到了代码失败的地方。它似乎与安全相关,但 JavaScript 已启用,我不知道该去哪里找...
T 2017-03-06 17:27:41:529 Browser.cpp(613) Entering Browser::GetDocumentFromWindow
T 2017-03-06 17:27:41:532 Script.cpp(49) Entering Script::Initialize
T 2017-03-06 17:27:41:532 Script.cpp(70) Entering Script::AddArgument(std::wstring)
T 2017-03-06 17:27:41:532 Script.cpp(105) Entering Script::AddArgument(VARIANT)
T 2017-03-06 17:27:41:532 Script.cpp(70) Entering Script::AddArgument(std::wstring)
T 2017-03-06 17:27:41:532 Script.cpp(105) Entering Script::AddArgument(VARIANT)
T 2017-03-06 17:27:41:532 Script.cpp(169) Entering Script::Execute
T 2017-03-06 17:27:41:532 Script.cpp(477) Entering Script::CreateAnonymousFunction
W 2017-03-06 17:27:41:539 Script.cpp(494) -2147024891 [Access is denied.]: Unable to execute code, call to IHTMLWindow2::execScript failed
W 2017-03-06 17:27:41:540 Script.cpp(180) Cannot create anonymous function
W 2017-03-06 17:27:41:540 ElementFinder.cpp(98) A JavaScript error was encountered executing the findElement atom.
如果有人看到或解决了这个问题,请帮助我!
谢谢
【问题讨论】:
-
当我遇到这个问题时,我将我的 IE 浏览器设置重置为默认值。通过重置检查一次。它对我有用。
-
不幸的是,我尝试了很多次。不过还是谢谢!
-
您说您“将所有区域的启用保护模式设置为禁用”。我想这意味着您也尝试过启用它?
-
我还假设您已确定“增强保护模式”已禁用?
-
我注意到您启用了本机事件但不需要窗口焦点。这可能无关紧要,但除非需要窗口焦点,否则您以后可能会遇到其他问题。见:github.com/SeleniumHQ/selenium/wiki/…
标签: java selenium selenium-webdriver internet-explorer-11