Chrome中的NoSuchElementException。找不到元素

时间:2013-10-31 09:29:58

标签: java google-chrome selenium webdriver selenium-chromedriver

我尝试点击以下元素:

选择专业......

我使用了以下代码:

尝试#1:

new Actions(driver).moveToElement(driver.findElement(By.xpath("//div[@class='dropbox_input  holder']"))).perform();

driver.findElement(By.xpath("//div[@class='dropbox_input  holder']")).click();

尝试#2:

new Actions(driver).moveToElement(driver.findElement(By.xpath("//div[contains(@class,'dropbox_input') and contains(@class, 'holder')]"))).perform();
            driver.findElement(By.xpath("//div[contains(@class,'dropbox_input') and contains(@class, 'holder')]")).click();

Attempt #3:

new Actions(driver).moveToElement(driver.findElement(By.cssSelector("div.strong div.dropbox_arrow"))).perform();
            driver.findElement(By.cssSelector("div.strong div.dropbox_arrow")).click();

预期产量是多少?你看到了什么呢? 预计会看到费用下拉,但看到新的Chrome窗口有空页。

Stacktrace:

org.openqa.selenium.NoSuchElementException: no such element
  (Session info: chrome=30.0.1599.101)
  (Driver info: chromedriver=2.1,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 19 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.37.0', revision: 'a7c61cbd68657e133ae96672cf995890bad2ee42', time: '2013-10-18 09:51:02'
System info: host: 'ws-31', ip: '10.0.255.179', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_26'
Session ID: 3aa1fe70bb49706a5d9db19c5c388277
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={chromedriverVersion=2.1}, rotatable=false, locationContextEnabled=true, version=30.0.1599.101, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=false, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=false, takesScreenshot=true}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:404)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:363)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)
    at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.java:101)
    at $Proxy12.findElement(Unknown Source)
    at org.openqa.selenium.support.events.EventFiringWebDriver.findElement(EventFiringWebDriver.java:180)

Selenium version: 2.37.0
OS: Win 7
Browser: Chrome
Browser version: 30.0.1599.101 m

相同的代码在FireFox中运行良好。

我附上屏幕截图以显示它的外观。enter image description here

2 个答案:

答案 0 :(得分:0)

您正在将ChromeDriver v2.1与Chrome v30一起使用。

将ChromeDriver更新到最新版本2.1不支持Chrome 30。

效果是任何调用(包括导航)都不起作用,因此任何find元素调用都会出错。

答案 1 :(得分:0)

首先,如果您检查了它,xpathselector是否真的有用,比方说,Firebug?如果是,请尝试此选项

new Actions(driver).moveToElement(driver.findElement(By.cssSelector("selector")))
    click.perform();