我正在尝试点击屏幕上非常明显的按钮,但是selenium webdriver会抛出此错误
[Parser] Running:
C:\Users\Administrator\AppData\Local\Temp\testng-eclipse\testng-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);
答案 0 :(得分:0)
所以这是我上面问题的解决方案。我使用Javascript a
点击了按钮JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("document.getElementById('loginbutton').click();");