1

我打开了 www.makemytrip.com 网站并尝试使用 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)
4

2 回答 2

3

另一种方法可能如下 -

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

ele.click();

希望这有效。

如果要在脚本中单击,C必须很小。

于 2012-07-02T06:15:15.570 回答
0

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

于 2012-07-02T06:12:37.693 回答