對於我的測試之一,我需要按下一個自舉開關按鈕,它具有以下HTML:如何使用Selenium Java Webdriver切換引導程序開關?
<div class="bootstrap-switch-container" style="width: 93px; margin-left: -31px;">
<span class="bootstrap-switch-handle-on bootstrap-switch-primary" style="width: 31px;">ON</span>
<span class="bootstrap-switch-label" style="width: 31px;">11111 </span>
<span class="bootstrap-switch-handle-off bootstrap-switch-default" style="width: 31px;">OFF</span>
<input name="form:taskDone" id="input_form:taskDone" type="checkbox">
</div>
我嘗試使用
By TASK_DONE_SWITCH_LOCATOR = By.id("input_form:taskDone");
taskDoneSwitch = wait.until(ExpectedConditions.elementToBeClickable(TASK_DONE_SWITCH_LOCATOR));
taskDoneSwitch.click();
然後我收到以下異常:
Timed out after 5 seconds
Build info: version: '2.8.0', revision: '14056', time: '2011-10-06 15:53:48'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_131'
Driver info: driver.version: unknown
org.openqa.selenium.TimeoutException
at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:220)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:188)
at hu.dual.webapp.customerservice.note.AbstractNoteTest.refreshEditPageTaskElements(AbstractNoteTest.java:161)
at hu.dual.webapp.customerservice.note.EditNoteTest.setTaskToDone(EditNoteTest.java:76)
堆棧跟蹤指向此行:
taskDoneSwitch = wait.until(ExpectedConditions.elementToBeClickable(TASK_DONE_SWITCH_LOCATOR));
然後它不會點擊。我怎樣才能點擊它?我嘗試使用其他字段和ExpectedConditions.visibilityOfElementLocated,但我仍然無法點擊它。
這不會拋出任何異常,但不會點擊按鈕!感謝您的關注! – brightpants
@brightpants也許你需要點擊其他元素?如'By.className(「bootstrap-switch-primary」);'或'By.className(「bootstrap-switch-default」);' – Guy
我試過了他們,但是這些消息是: 未知錯誤:元素 ...在點(218,686)處不可點擊。其他元素將會收到點擊: