[英]Selenium is not selecting the correct value
我正在使用硒来测试具有选择选项和一个输入类型文本的网页。
手动并使用selenium IDE可以正常工作,但是当我将测试用例导出到Java Junit时,我可以看到下拉单击,但是selenium没有选择该值,它只是在扩展下拉列表。
我能做什么?
让我们检查一下我的代码:
Select dropdown = new Select(driver.findElement(By.id("type")));
dropdown.selectByVisibleText("Celcius");
考虑一下我的表单,例如:
<form action="doit">
<select name="type" id = "type">
<option value = "fail"> Fail </option>
<option value = "celcius"> Celcius </option>
</select>
<input type="number" name="num" id="num">
</form>
有时这种方法行不通。 如果选项标签之间的文本在标签前后有空格,则可能会发生这种情况。 例如。
1. <option> Fail </option>
2. <option>Fail</option>
在上面的示例中1和2不同。 所以你可以这样使用
driver.findElement(By.id("type")).click(); // this will expand the list
driver.findElement(By.xpath("//select[@id='type']/option[contains(text(),'Celcius')]")).click();
也可以尝试直接单击。 如果元素是可存活的,它将起作用
driver.findElement(By.xpath("//select[@id='type']/option[contains(text(),'Celcius')]")).click();
driver.findElement(By.id( “类型”))的SendKeys( “摄氏度”);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.