尝试使用selenium webdriver使用JavascriptExecutor单击单选按钮时获取错误

时间:2012-07-02 06:04:15

标签: javascript selenium webdriver

我已经打开www.makemytrip.com网站并尝试点击Round Trip单选按钮 JavascriptExecutor。

Driver.get("http://www.makemytrip.com/");
((JavascriptExecutor) Driver).executeScript("document.getElementById('roundtrip_r').Click();");

执行脚本时,我在控制台上出现以下错误

Exception in thread "main" org.openqa.selenium.WebDriverException: null (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 14 milliseconds
Build info: version: '2.24.1', revision: '17205', time: '2012-06-19 16:53:24'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.6.0_27'
Driver info: driver.version: RemoteWebDriver
Session ID: 9e0bc318-7cea-4351-b83d-6f0f024b7972
    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.ErrorHandler.createThrowable(ErrorHandler.java:188)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:472)
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:381)

2 个答案:

答案 0 :(得分:3)

另一种方式可能如下 -

WebElement ele = (WebElement) ((JavascriptExecutor) driver).executeScript("return document.getElementById('roundtrip_r');");

ele.click();

希望这有效。

如果要在脚本中单击,

C 必须小。

答案 1 :(得分:0)

Click()的第一个字母必须很小。