发布于2021-11-28 10:29 阅读(218) 评论(0) 点赞(0) 收藏(1)
在我的 Selenium 测试代码中,我有几行
这是代码
WebElement selectAllElement = driver.findElement(By.id("filterForm:selectAll"));
if (selectAllElement.isSelected())
{
selectAllElement.click();
}
Select selectLocation = new Select(new WebDriverWait(driver, 30)
.until(ExpectedConditions
.presenceOfElementLocated(By.id("filterForm:selectLocation"))));
selectLocation.selectByVisibleText(location);
WebElement filterButton = driver.findElement(By.id("filterForm:filterButton"));
filterButton.click();
我StaleElementReferenceException
在尝试检索页面上的 Select 元素时收到了一个,为了尝试解决这个问题,我在这个元素上添加了一个显式等待,如上面的代码所示。
然而,我仍然得到一个 StaleElementReferenceException
编辑(这些元素的 HTML)
<form id="filterForm" name="filterForm" method="post" action="/UsersJSFMavenApplication/faces/index.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="filterForm" value="filterForm" />
<input id="filterForm:selectAll" type="checkbox" name="filterForm:selectAll" checked="checked" title="allUsers" onclick="mojarra.ab(this,event,'valueChange',0,'filterForm:filterGrid usersForm')" />All users<table id="filterForm:filterGrid">
<tbody>
<tr>
<td><input id="filterForm:userName" type="text" name="filterForm:userName" disabled="disabled" /></td>
<td><select id="filterForm:selectLocation" name="filterForm:selectLocation" size="1" disabled="disabled"> <option value="Keynsham">Keynsham</option>
<option value="London">London</option>
<option value="Silicon Valley">Silicon Valley</option>
</select></td>
<td><input id="filterForm:filterButton" type="submit" name="filterForm:filterButton" value="Filter" disabled="disabled" /></td>
</tr>
</tbody>
</table>
<input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="-8198231560613594227:-8434387391056535341" autocomplete="off" />
</form>
我已经设法通过更改解决了这个问题
Select selectLocation = new Select(new WebDriverWait(driver, 30)
.until(ExpectedConditions
.presenceOfElementLocated(By.id("filterForm:selectLocation"))));
到
Select selectLocation = new Select(new WebDriverWait(driver, 30)
.until(ExpectedConditions
.elementToBeClickable(By.id("filterForm:selectLocation"))));
我不知道为什么它会有所作为,也许有人可以发表一些评论。
作者:黑洞官方问答小能手
链接:http://www.javaheidong.com/blog/article/337841/7e282dc0c34012fe1346/
来源:java黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 java黑洞网 All Rights Reserved 版权所有,并保留所有权利。京ICP备18063182号-2
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!