0

我试图点击以下元素:

选择专业...

我使用了以下代码:

尝试#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 窗口带有空白页面。

堆栈跟踪:

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 中运行良好。

我附上屏幕截图以显示它的外观。在此处输入图像描述

4

2 回答 2

0

首先,如果您签入,例如 Firebug,您的xpathselector真的有效吗?如果是,请尝试此选项

new Actions(driver).moveToElement(driver.findElement(By.cssSelector("selector")))
    click.perform();
于 2013-11-03T18:32:26.147 回答
0

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

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

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

于 2013-10-31T10:51:48.327 回答