无法从选择框中选择选项
无法使用 selenium 2 firefox(或 chrome)驱动程序在选择框中选择项目
<select id="activations_month" name="activations[month]">
<option value="April 2011">April 2011</option>
<option value="May 2011">May 2011</option>
<option value="June 2011">June 2011</option>
<option value="July 2011">July 2011</option>
<option value="August 2011">August 2011</option>
<option selected="selected" value="September 2011">September 2011</option>
</select>
Select dropDown = new Select(sDriver.findElement(By.id("activations_month"))); dropDown.selectByValue("2011 年 8 月");
我尝试过按值选择、按索引选择、按可见文本选择以及取消选择,但都没有做任何事情。我的 try catch 没有捕获异常,它退出回到 testNG 测试运行程序并进入下一个方法
这确实工作正常并返回正确的值
List<WebElement> options = dropDown.getOptions();
System.out.println(options.size());
System.out.println(options.get(0).getText());
System.out.println(options.get(1).getText());
Cannot select an item in a select box using selenium 2 firefox (or chrome) driver
<select id="activations_month" name="activations[month]">
<option value="April 2011">April 2011</option>
<option value="May 2011">May 2011</option>
<option value="June 2011">June 2011</option>
<option value="July 2011">July 2011</option>
<option value="August 2011">August 2011</option>
<option selected="selected" value="September 2011">September 2011</option>
</select>
Select dropDown = new Select(sDriver.findElement(By.id("activations_month")));
dropDown.selectByValue("August 2011");
I have tried select by value, by index, by visible text and deselecting and all just fail to do anything. My try catch does not catch an exception it exits back out into the testNG test runner and onto the next method
This does work fine and returns the correct values
List<WebElement> options = dropDown.getOptions();
System.out.println(options.size());
System.out.println(options.get(0).getText());
System.out.println(options.get(1).getText());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无论问题是什么,这都应该可以解决您的问题。这不是选择选项的最佳方法,但它应该有效:
This should work around your problem, whatever it is. Not the greatest way to select an option but it should work:
这可能不是理想的解决方案,但为了保持简单(并使其正常工作),您是否尝试过实例化
WebDriverBackedSelenium
?接下来是常规的——
This may not be the ideal solution, but in the interest of keeping this simple (and to get it to work), have you tried instantiating a
WebDriverBackedSelenium
?Followed by the conventional -