获取 org.openqa.selenium.StaleElementReferenceException:元素不再附加到 DOM
list = driver.findElements(By.cssSelector(listLocator));
for (WebElement listItem : list) {
checkbox = listItem.findElement(By.cssSelector(checkboxLocator));
checkbox.click();
String path = checkbox.getCssValue("background-image"));
}
执行后 checkbox.click();
我无法在checkbox
元素上调用任何方法
对应图片:
我的定位器是
listLocator = ul[class="planList"] > li[class="conditionsTextWrapper"]
checkboxLocator = label[role="button"] > span[class="ui-button-text"]
我在执行之前的 HTML 源代码checkbox.click()
:
<ul class="planList">
<li class="conditionsTextWrapper" >
<input name="chkSubOpt" type="checkbox">
<label class="check ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" for="CAT_5844" aria-pressed="false" role="button">
<span class="ui-button-text"></span>
</label>
<label class="conditionsText">Eat at least 5 fruits and vegetables every day</label>
</li>
</ul>
执行后checkbox.click()
:
<ul class="planList">
<li class="conditionsTextWrapper" >
<input name="chkSubOpt" type="checkbox">
<label class="check ui-button ui-widget ui-state-default ui-corner-all ui-state-active ui-button-text-only" for="CAT_5844" aria-pressed="true" role="button" aria-disabled="false">
<label class="conditionsText">Eat at least 5 fruits and vegetables every day</label>
</li>
</ul>