我能够在webdriver中找到以下版本的元素,但是最新版本无法找到该元素
driver.findElement(By.id("dropdownMenu")).click();
在控制台中获取此内容:
1491224447464 geckodriver INFO Listening on 127.0.0.1:14273
1491224448607 mozprofile::profile INFO Using profile path C:\Users\COMPIN~1\AppData\Local\Temp\rust_mozprofile.btmAM70uon4k
1491224448614 geckodriver::marionette INFO Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe with args []
1491224448633 geckodriver::marionette INFO Connecting to Marionette on localhost:65438
1491224450952 Marionette INFO Listening on port 65438
Apr 03, 2017 6:30:53 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
JavaScript warning: https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js, line 1: Using //@ to indicate sourceMappingURL pragmas is deprecated. Use //# instead
JavaScript error: https://qa.xyz.com/assets/js/custom.js?1491224506, line 12601: TypeError: $(...).select2 is not a function
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: #dropdownMenu
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: '5234b32', time: '2017-03-10 09:00:17 -0800'
System info: host: 'CO-PC', ip: '169.254.250.92', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\CO~1\AppData\Local\Temp\rust_mozprofile.btmAM70uon4k, rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=53.0, platformVersion=6.1, moz:processID=6952, browserName=firefox, platformName=windows_nt}]
Session ID: 76cd7017-8b8b-463f-84a4-c580b6a58bf8
*** Element info: {Using=id, value=dropdownMenu}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:133)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:99)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:43)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:371)
at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:420)
at org.openqa.selenium.By$ById.findElement(By.java:218)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
at WebApp.mc.main(mc.java:29)
答案 0 :(得分:0)
请确保以下内容:
您正在使用最新版本的Selenium。 v 3.x.x&最新版本的gecko驱动程序以及最新版本的Mozilla Firefox浏览器。
要使用Selenium 3.x.x,您需要下载合适的gecko驱动程序。
在编写代码时,您需要在开头提及以下内容:
System.setProperty("webdriver.gecko.driver","C:\\your_location\\geckodriver.exe");
然后继续初始化您的驱动程序。
一旦您访问该网址,就会为ajax扩展程序引入ImplicitlyWait& js扩展加载。
由于错误是“NoSuchElementException”,请检查是否可以使用该ID将元素标识为唯一元素。
否则尝试使用其他属性,例如name / css / xpath。
如果这有助于您,请告诉我。