我试图点击一个按钮,这是非常可见的屏幕上,但硒webdriver抛出这个错误
[Parser] Running:
C:UsersAdministratorAppDataLocalTemptestng-eclipsetestng-customsuite.xml
FAILED: Myclass
org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for visibility of element located by By.selector: #loginbutton
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'MININT-K353O1P', ip: '192.168.1.5', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_51'
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:259)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:228)
at test.test.testEmailGenerator(test.java:33)
... Removed 22 stack frames
===============================================
test.test
Tests run: 1, Failures: 1, Skips: 0
===============================================
===============================================
test
Total tests run: 1, Failures: 1, Skips: 0
===============================================
[org.testng.internal.PoolService] Shutting down poolservice org.testng.internal.PoolService@95e522c terminated:false
我试图验证的按钮有html标签如下:
<input id="loginbutton" type="submit" name="loginbutton" value="" onclick="clkLgn()" style="width: 59px; height: 20px"></input>
到目前为止我的基本代码:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement BTN = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#loginbutton")));
BTN.sendKeys(Keys.RETURN);
所以这是我上面问题的解决方案。我用Javascript点击了按钮a
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("document.getElementById('loginbutton').click();");