本文介绍了使用Internet Explorer 11和Selenium(任何版本)和IEWebDriver(任何版本)都找不到任何元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经到处搜索了一个答案,我找不到任何解决方法。我试图在IE11中运行我的Selenium测试。所有其他浏览器都可以正常工作(包括Edge)。如下的简单测试将导致问题......

I've searched all over for an answer and I can't find any fix to my issue. I am trying to run my Selenium tests in IE11. All other browsers work fine (including Edge). A simple test as follows will cause the issue...

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,但它无法在任何页面上找到任何元素。再一次,我知道人们有这个问题,但没有任何建议解决了我的问题。这是我每次都回来的错误:

IE11 will launch and navigate to a URL but it cannot find any elements anywhere on any page. Again, I'm aware people have had this issue but no suggestions have fixed my problem. This is the error i get back every time:

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)

这是我尝试过的事情。 。

Here is what I've tried/done...


  1. 将所有区域的启用保护模式设置为禁用

  2. 在高级设置上设置允许脚本选项标签或IE o ptions

  3. 尝试了人类所知的每一个IEDriver功能,例如setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION,true);

  4. 尝试IE11 32和64位

  5. 尝试查找元素,类,标记名及其他所有元素定位器无济于事。

  6. 为IE的32和64位实例添加了2个注册表项BFCACHE

  7. 哭得很厉害

  1. Set Enabled Protected Mode to disabled for all zones
  2. Set Allow Scripting option on the advanced tab or IE options
  3. Tried every IEDriver capability known to man e.g. setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION,true);
  4. Tried IE11 32 and 64bit
  5. Attempted to find an element by, class, tagname and all the rest of the locators to no avail.
  6. Added the 2 registry keys BFCACHE for both 32 and 64bit instances of IE
  7. Cried a lot

下面是附加的日志,我找到了代码落在的地方。它似乎与安全相关,但启用了JavaScript,我不知道还有什么地方可以看...

Below is the attached logs and I've located where the code falls over. It seems to be security related but JavaScript is enabled and I don't know where else to look...

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.

如果有人看到或解决了这个问题,请帮助我!

If anyone has seen or fixed this issue, please help me!

谢谢

推荐答案

之前,我使用 IE11 与Selenium WebDriver 2.5 .3和IEDriver -2.53.0。我遇到了同样的问题。我通过以编程方式设置 IE 的某些属性来更改功能,并且它有效。以下是代码段:

Earlier, I was using IE11 with Selenium WebDriver 2.5.3 and IEDriver -2.53.0. I got the same issue. I changed the capabilities by setting some properties for IE programmatically and it worked. Here's the code snippet:

    DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
    caps.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, Configuration.getConfig("My URL"));
    caps.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);

这篇关于使用Internet Explorer 11和Selenium(任何版本)和IEWebDriver(任何版本)都找不到任何元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 08:13