gpt4 book ai didi

java - 无法在 Select with Selenium 中选择选项

转载 作者:行者123 更新时间:2023-12-01 17:42:04 36 4
gpt4 key购买 nike

当我尝试在 <select> 中选择选项时遇到问题 Selenium 。

Select select = new Select(element);
actions.moveToElement(element);
select.selectByValue("100000");

这只是给了我 ElementClickIntercepted 。尝试点击它也会给我 ElementClickIntercepted 。尝试用 JS 点击它会给我一个 NullPointerException 。我可以在 Firefox 中使用元素选择器轻松选择它,因此选择上方没有任何内容阻止我单击它。

什么是拦截点击?通常当因为一个元素覆盖另一个元素时,它会在测试结果中告诉我,但这里不会。

<div class="pull-left">
<select name="nb" class="form-control">
<option value="10">10</option><option value="20">20</option><option value="50">50</option><option value="100000">All</option>
</select>
</div>

选择 xPath:

//select[@name="nb"]

并且它是页面上唯一的选择。

最佳答案

试试这个:

WebDriverWait wait = new WebDriverWait(driver, 40);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//select[@name='nb']")));
Select select = new Select(element);
actions.moveToElement(element);
select.selectByValue("100000");

关于java - 无法在 Select with Selenium 中选择选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59897857/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com