Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 硒:Internet Explorer中的无接触元素例外_Java_Internet Explorer_Selenium_Nosuchelementexception_Remotewebdriver - Fatal编程技术网

Java 硒:Internet Explorer中的无接触元素例外

Java 硒:Internet Explorer中的无接触元素例外,java,internet-explorer,selenium,nosuchelementexception,remotewebdriver,Java,Internet Explorer,Selenium,Nosuchelementexception,Remotewebdriver,我正在尝试将一个用于内部Webapp的Selenium脚本从Selenium IDE移植到Java中带有RemoteWebDrivers的Selenium网格设置 这些脚本在Chrome和Firefox上运行良好,但在InternetExplorer中不起作用。每次我试图在页面中查找一个元素时,我只会得到一个NoTouchElementException(页面本身的加载很好) 使用Wikipedia页面显示相同行为的示例代码: public class Wikipedia_test_IE {

我正在尝试将一个用于内部Webapp的Selenium脚本从Selenium IDE移植到Java中带有RemoteWebDrivers的Selenium网格设置

这些脚本在Chrome和Firefox上运行良好,但在InternetExplorer中不起作用。每次我试图在页面中查找一个元素时,我只会得到一个NoTouchElementException(页面本身的加载很好)

使用Wikipedia页面显示相同行为的示例代码:

public class Wikipedia_test_IE {
 private WebDriver driver = null;
 private String baseUrl = null;
 private boolean acceptNextAlert = true;
 private StringBuffer verificationErrors = new StringBuffer();


 @Before
 public void setUp() throws Exception {
//      DesiredCapabilities cap = DesiredCapabilities.firefox();
 DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
 cap.setCapability(CapabilityType.VERSION, "9");

        driver = new RemoteWebDriver (new URL("http://192.168.1.230:4444/wd/hub"), cap);    
        baseUrl = "https://en.wikipedia.org/wiki/Rosetta_%28spacecraft%29";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
 }

 @Test
 public void testAKTargobankTestfall1KN() throws Exception {
      driver.get(baseUrl);
      driver.findElement(By.linkText("space probe")).submit();
 }
}
我尝试过使用findElement(By.Id)和findElement(By.cssSelector)——没有效果。在页面加载和选择之间设置延迟也没有效果,使用click代替submit也没有效果

我已经启用了IE驱动程序的调试日志记录,但是输出并不能帮助我理解问题可能是什么——希望其他人可以

server.cc(239) Command: POST /session {"desiredCapabilities":{"platform":"WINDOWS","ensureCleanSession":true,"browserName":"internet explorer","version":"9"}}
IESession.cpp(43) Mutex acquired for session initalization
IESession.cpp(105) Releasing session initialization mutex
command.cc(33) Raw JSON command: { "command" : "newSession", "locator" : { }, "parameters" : {"desiredCapabilities":{"platform":"WINDOWS","ensureCleanSession":true,"browserName":"internet explorer","version":"9"}} }
BrowserFactory.cpp(68) Ignoring Protected Mode Settings: 0
BrowserFactory.cpp(71) Checking validity of Protected Mode settings.
BrowserFactory.cpp(984) Detected IE version: 9, detected Windows version: 6
BrowserFactory.cpp(1074) Found Protected Mode setting value of 0 for zone 1
BrowserFactory.cpp(1074) Found Protected Mode setting value of 0 for zone 2
BrowserFactory.cpp(1074) Found Protected Mode setting value of 0 for zone 3
BrowserFactory.cpp(1074) Found Protected Mode setting value of 0 for zone 4
BrowserFactory.cpp(74) Has Valid Protected Mode Settings: 1
BrowserFactory.cpp(170) Starting IE using the IELaunchURL API
BrowserFactory.cpp(124) IE launched successfully with process ID 2188
BrowserFactory.cpp(130) Process with ID 2188 is executing iexplore.exe
BrowserFactory.cpp(313) Ignoring zoom setting: 0
BrowserFactory.cpp(581) Browser zoom level is 100%
IECommandExecutor.cpp(650) Persistent hovering set to: 1
ProxyManager.cpp(118) Using existing system proxy settings.
server.cc(308) Response: {"sessionId":"4aba017b-91e9-4f48-9f9f-f38b0464bb6b","status":303,"value":"/session/4aba017b-91e9-4f48-9f9f-f38b0464bb6b"}


server.cc(239) Command: GET /session/4aba017b-91e9-4f48-9f9f-f38b0464bb6b {}
command.cc(33) Raw JSON command: { "command" : "getSessionCapabilities", "locator" : { "sessionid" : "4aba017b-91e9-4f48-9f9f-f38b0464bb6b" }, "parameters" : {} }
IECommandExecutor.cpp(544) No alert handle is found
server.cc(308) Response: {"sessionId":"4aba017b-91e9-4f48-9f9f-f38b0464bb6b","status":0,"value":{"browserAttachTimeout":0,"browserName":"internet explorer","cssSelectorsEnabled":true,"elementScrollBehavior":0,"enableElementCacheCleanup":true,"enablePersistentHover":true,"handlesAlerts":true,"ie.browserCommandLineSwitches":"","ie.ensureCleanSession":false,"ie.forceCreateProcessApi":false,"ie.usePerProcessProxy":false,"ignoreProtectedModeSettings":false,"ignoreZoomSetting":false,"initialBrowserUrl":"http://localhost:15278/","javascriptEnabled":true,"nativeEvents":true,"platform":"WINDOWS","requireWindowFocus":false,"takesScreenshot":true,"unexpectedAlertBehaviour":"dismiss","version":"9"}}

server.cc(239) Command: POST /session/4aba017b-91e9-4f48-9f9f-f38b0464bb6b/timeouts/implicit_wait {"ms":30000}
command.cc(33) Raw JSON command: { "command" : "implicitlyWait", "locator" : { "sessionid" : "4aba017b-91e9-4f48-9f9f-f38b0464bb6b" }, "parameters" : {"ms":30000} }
IECommandExecutor.cpp(544) No alert handle is found
server.cc(308) Response: {"sessionId":"4aba017b-91e9-4f48-9f9f-f38b0464bb6b","status":0,"value":null}

server.cc(239) Command: POST /session/4aba017b-91e9-4f48-9f9f-f38b0464bb6b/url {"url":"https://en.wikipedia.org/wiki/Rosetta_%28spacecraft%29"}
command.cc(33) Raw JSON command: { "command" : "get", "locator" : { "sessionid" : "4aba017b-91e9-4f48-9f9f-f38b0464bb6b" }, "parameters" : {"url":"https://en.wikipedia.org/wiki/Rosetta_%28spacecraft%29"} }
IECommandExecutor.cpp(544) No alert handle is found
Browser.cpp(421) Navigate Events Completed.
Browser.cpp(452) Browser ReadyState is not '4', indicating 'Complete'; it was 1
Browser.cpp(421) Navigate Events Completed.
Browser.cpp(437) Browser busy property is true.
(最后两行重复几次)


有什么想法吗?

您可能应该使用
click()
,而不是
submit()


我在测试中也犯了这样的错误,在FF上效果很好,但在IE上没有

我可以建议你:

  • 检查IE上的保护模式设置
  • 禁用IE驱动程序上的本机事件
  • 在这些特殊情况下使用JavaScript(我认为这是最糟糕的情况)
这是IE驱动程序的已知问题


尝试使用
InternetExplorerDriver
而不是
RemoteWebDriver
,通常情况下,这不会有什么区别,但在IE中,一切都是可能的

我遇到了类似的问题,我最终得到了以下代码,这些代码对我很有用:

@Before
public void setUp() {
   //... some irrelevant Code ... 

   System.setProperty("webdriver.ie.driver", "Path to IEDriver.exe");
   InternetExplorerDriver driver = new InternetExplorerDriver();

   //... some irrelevant Code ...
}

谢谢你的帮助。为了回答上面提到的一些问题,我应该在原始帖子中包括这些问题:

-是的,确实是9 -我已经在所有安全区域将保护模式设置为启用 -使用“单击”而不是“提交”没有任何区别(最初)

碰巧运行Selenium节点的VM在夜间应用了安全更新,其中包括IE的安全更新

起初,我收到了一条与以前不同的错误消息——IE无法找到刚刚打开的浏览器窗口,而且窗口也没有关闭。更新已重置所有安全设置

在重新启用保护模式后,一切现在都正常工作。正如Richard指出的,我确实需要将find元素改为.click(),而不是.submit()


所以,现在一切都正常了,我不知道为什么。再次感谢

您可以用以下方式编写代码:

while(true) {
    try {
        driver.findElement(By.linkText("space probe")).submit();
        break;
    } catch (Exception e) {
        continue;
    }
}

我这样编写代码,以便线程搜索直到成功。当隐式使用
wait
时,浏览器将只等待最长时间。但是,您的浏览器页面加载可能已经完成,但所需的部分是通过ajax调用加载的。在这种情况下,您的程序将抛出一个错误。

我假设您正在运行的实际上是IE9?这个错误听起来像是某种程度上阻止了JS的执行。也许检查一下你的安全设置?还要验证它是否发生在另一个站点上?也许可以在IE的开发者控制台中尝试一个CSS选择器,以确保像它这样基本的东西能够正常工作?
@Before
public void setUp() {
   //... some irrelevant Code ... 

   System.setProperty("webdriver.ie.driver", "Path to IEDriver.exe");
   InternetExplorerDriver driver = new InternetExplorerDriver();

   //... some irrelevant Code ...
}
while(true) {
    try {
        driver.findElement(By.linkText("space probe")).submit();
        break;
    } catch (Exception e) {
        continue;
    }
}