2012-07-02 29 views
1

我打開www.makemytrip.com網站,並嘗試點擊使用 JavaScriptExecutor的往返單選按鈕。獲取錯誤,同時嘗試使用JavascriptExecutor使用硒webdriver點擊單選按鈕

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) 

回答

3

另一種方式可能是因爲如下─

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

ele.click(); 

希望這個作品。

C如果您想在腳本中單擊並且必須很小。

0

點擊的第一個字母()一定要小。

相關問題