实施InternetExplorerDriver的过程中发生NoSuchElementExcepti

2019-10-21 22:24发布

目前硒远程驱动器的工作。 执行工作正常使用Chrome远程驱动器,但不与IE浏览器的工作。 这NoSuchElementException异常后显示的IE浏览器启动

类似的问题,我发现在低于网址,我实现了所有指定的解决方案仍然不是为我工作。 硒实施InternetExplorerDriver的过程中发生NoSuchElementException异常的webdriver

推出硒格-集线器使用:(机器A):

java -jar selenium-server-standalone-2.44.0.jar -role hub  

推出硒格-节点使用:(机器B):

java -jar selenium-server-standalone-2.44.0.jar -role webdriver -hub http://xx.x.xx.xx:4444/grid/register -port 5566 -browser browserName="internet explorer",version=8.0,platform=WINDOWS -Dwebdriver.ie.driver=\\SeleniumDrivers\IEDriverServer.exe

代码的测试脚本。(Eclipse中)

DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setBrowserName("internet explorer");
capabilities.setPlatform(Platform.WINDOWS);             
capabilities.setCapability("ie.ensureCleanSession", true);    
capabilities.setCapability("forceCreateProcessApi", true);
capabilities.setCapability("ignoreProtectedModeSettings", true);
System.setProperty("webdriver.ie.driver", "\\SeleniumDrivers\\IEDriverServer.exe");
WebDriver driver = new RemoteWebDriver(new URL("http://MachineBIPAddress:5566/wd/hub"),capabilities);    

//示例代码。

driver.get("www.google.com");
driver.findElement(By.id("gbqfqw")).sendKeys("test");
driver.findElement(By.name("btnG")).click();

在执行:

IE browser is launched in Machine B and then error "org.openqa.selenium.NoSuchElementException:" displayed.


log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with css selector == a[class*='searchbtn'] (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 20.13 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'xxxxxxx', ip: 'xxx.xx.xx.xx', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_31'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=true, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:27297/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=true, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}]
Session ID: 445a8c44-fb7c-4f05-8b5a-f025787ffea5
Command duration or timeout: 23.98 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:03:00'
System info: host: 'xxxxxx', ip: 'xx.x.xxx.xx', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_31'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{browserAttachTimeout=0, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=true, elementScrollBehavior=0, ie.browserCommandLineSwitches=, webdriver.remote.sessionid=5daa42d6-5f04-46ac-821a-59dcb261edd1, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:27297/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=true, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}]
Session ID: 5daa42d6-5f04-46ac-821a-59dcb261edd1
    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:408)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:441)
    at org.openqa.selenium.By$ByCssSelector.findElement(By.java:426)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
    at dashBoard_Automation.dashboardSerach.main(xxxx.java:86)
Caused by: org.openqa.selenium.remote.ScreenshotException: Screen shot has been taken
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:03:00'

Answer 1:

我只是想你的IE8,IE10和IE11测试。 在IE10和IE11的一切工作完全正常。 IE8不会谷歌网页上的工作,因为这些按钮将在快速搜索结果被隐藏。

一个可能的解释是,在本例中您提供您正在使用“btnG”按钮。 您键入一些文字后才那个按钮是可见的。 也许你需要等待,直到显示按钮。

您可以手动完成测试你的测试机上,并检查“btnG”其实呢?

更新 :所有的机器都安装了IE浏览器的相应版本的虚拟机。 测试机是通过设置启动硒服务器

javaw.exe的-Dwebdriver.chrome.driver = “chromedriver.exe” -Dwebdriver.ie.driver = “IEDriverServer.exe” -Dphantomjs.binary.path = “phantomjs.exe” 罐子硒 - 服务器 - 独立-2.41.0的.jar -port 4444

[TestCase("IE8", "http://xxx-xxx-tuai04:4444/wd/hub")]
[TestCase("IE10", "http://xxx-xxx-tuai01:4444/wd/hub")]
[TestCase("IE11", "http://xxx-xxx-tuai02:4444/wd/hub")]
public void ClickSignInInInternetExplorerThroughRemoteDriver(string version, string url)
{
    using (var driver = new RemoteWebDriver(new Uri(url), DesiredCapabilities.InternetExplorer()))
    {

        driver.Navigate().GoToUrl("https://www.google.com/?gws_rd=cr,ssl&fg=1");
        driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));

        var element = driver.FindElementById("gbqfqw");
        element.SendKeys("test");

        var btn = driver.FindElementByName("btnG");
        btn.Click();
    }

}


Answer 2:

感谢您的回复。

终于,我发现有两个原因,测试失败IE 11.现在解决了他们

  1. Windows更新KB3025390导致问题
  2. 新增capabilities.setCapability( “nativeEvents”,假);

测试的webdriver不IE11运行



文章来源: Selenium Remote Driver - NoSuchElementException is occurred during implementation of InternetExplorerDriver