可以在无头浏览器中使用javascript执行点击,因为click()操作在我的情况下不起作用。由于点击使用javascript正在Firefox浏览器上工作,但它无法在无头浏览器中工作,我收到以下错误
org.openqa.selenium.WebDriverException: arguments[0] is undefined
Build info: version: '2.51.0', revision: '1af067d', time: '2016-02-05 19:15:17'
System info: host: 'devui1.pdx.aws', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-573.7.1.el6.x86_64', java.version: '1.7.0_95'
Driver info: driver.version: unknown
Command duration or timeout: 5.41 seconds
Build info: version: '2.48.2', revision: '41bccdd10cf2c0560f637404c2d96164b67d9d67', time: '2015-10-09 13:08:06'
System info: host: 'Admin-HP', ip: '10.242.2.4', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_102'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false,databaseEnabled=true, handlesAlerts=true, version=38.6.0, platform=LINUX, nativeEvents=false, acceptSslCerts=true, webdriver.remote.sessionid=be53c1d5-b50b-47d4-afba-e0c8e88517aa, locationContextEnabled=true, webStorageEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: be53c1d5-b50b-47d4-afba-e0c8e88517aa
代码:
try{
WebElement Checkbox = driver.findElement(By.xpath(strSelectChkBox));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", Checkbox);
oGeneric.sleepTimer(5);
constant.objLogs.writeLog("Clicked on Variant filter check box ");
}
catch (TimeoutException toe ){
constant.objLogs.writeLog("Failed to Clicked on Variant ");
throw(toe);
}