【发布时间】:2019-05-05 16:00:16
【问题描述】:
问题:有几个具有相同 ID 的单选按钮,我需要单击这些按钮。第一个单选按钮获得点击,第二个单选按钮获得StaleElementReferenceException。
任何人都可以建议我如何处理它,以便当我单击第二个单选按钮时它不会抛出 StaleElementReferenceException
HTML:
<solvup-radio-type _ngcontent-c7="" _nghost-c10=""><div _ngcontent-c10="" class="validation-error ng-untouched ng-pristine ng-invalid">
<solvup-label _ngcontent-c10="" _nghost-c33=""><label _ngcontent-c33="" class="control-label">
Have you been able to resolve the issue based on this information? <!----><span _ngcontent-c33="" class="required-mark">*</span>
</label>
<solvup-tooltip _ngcontent-c33="" _nghost-c36=""><!---->
</solvup-tooltip>
</solvup-label>
<!----><div _ngcontent-c10="" class="radio">
<label _ngcontent-c10="">
<input _ngcontent-c10="" type="radio" id="ts_note_questions" class="ng-untouched ng-pristine ng-invalid">
Yes, issue is resolved - close case
</label>
</div><div _ngcontent-c10="" class="radio">
<label _ngcontent-c10="">
<input _ngcontent-c10="" type="radio" id="ts_note_questions" class="ng-untouched ng-pristine ng-invalid">
No - continue to next step
</label>
</div>
</div>
<solvup-hint-text _ngcontent-c10="" _nghost-c34=""><!----><p _ngcontent-c34="" class="help-block"></p>
</solvup-hint-text>
<solvup-validation-messages _ngcontent-c10="" _nghost-c35=""><!---->
<!----><div _ngcontent-c35="" class="form-group">
<small _ngcontent-c35="" class="err"><i _ngcontent-c35="" aria-hidden="true" class="fa fa-exclamation-triangle"></i> Please select an option</small>
</div>
</solvup-validation-messages>
</solvup-radio-type>
硒代码:
@Given("^User fills details in First of Five Troubleshooting page$")
public void user_fills_details_in_First_of_Five_Troubleshooting_page() throws Throwable {
Thread.sleep(2000);
List<WebElement> li = driver.findElements(By.className("radio"));
Actions ob = new Actions(driver);
ob.moveToElement(li.get(1));
ob.click(li.get(1));
Action action = ob.build();
action.perform();
}
请提出建议。
【问题讨论】:
-
StaleElement 通常在执行操作时重新加载页面的 dom 时出现。要解决此问题,您可以等待几秒钟重新加载页面然后重新定位 Web 元素并执行操作跨度>
-
@ShekharSwami 我应用了隐式等待。但它不工作
-
隐式不起作用.. Thread.sleep
-
@ShekharSwami 正如您在代码中看到的那样,我已经在使用 thread.sleep 但它也不起作用
标签: selenium selenium-webdriver automation ui-automation browser-automation