验证当前对下拉菜单的选择 [英] Verifying current selection of a dropdown menu
问题描述
使用Selenium Webdriver(Java)
我需要验证当用户在另一个会话中返回该页面时,是否保存了下拉菜单中的选定值。 / p>
下拉菜单很简单,它只是更改搜索后每页显示的记录数。
值分别为5、10、25、50和100。
使用getText()只是返回数组中的值。我需要验证如果用户选择25,则返回该特定页面时该值是相同的。一个简单的assert语句在这里不起作用,因为值 25可以出现在其他字段中。
我也尝试了Select的各种用法,但没有成功。 / p>
我将不胜感激。如果我错过了任何关键信息,请随时指出,我将更新帖子。
您需要使用 Select
类
IWebElement selectElement = driver.FindElement(By.Id (ID));
SelectElement selectedValue =新的SelectElement(selectElement);
string selectedText = selectedValue.SelectedOption.Text;
用C#编写的矿井。但是Java也相当接近。请参见此
编辑:
使用 getFirstSelectedOption()。getText()
代替 SelectedOption.Text;
根据api文档
Using Selenium Webdriver (Java)
I need to verify that a selected value from a dropdown menu is saved when a user returns to that page in another session.
The dropdown is simple, it just changes the number of records displayed per page after a search.
The values are 5, 10, 25, 50 and 100.
Using getText() simply returns the values in the array. I need to verify that if a user chooses, say, 25, that that value is the same when returning to this particular page. A simple assert statement doesn't work here because the value "25" can be present in other fields.
I've also tried various uses of Select without success.
I'd appreciate any suggestions. If I've missed any key information, feel free to point it out and I will update the post.
You need to use Select
class
IWebElement selectElement = driver.FindElement(By.Id("id"));
SelectElement selectedValue = new SelectElement(selectElement);
string selectedText = selectedValue.SelectedOption.Text;
Mine written in C#. But Java is fairly close as well.See this
EDIT:
you should be using getFirstSelectedOption().getText()
instead of SelectedOption.Text;
according to the api doc
这篇关于验证当前对下拉菜单的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!