Selenium: How to verify menu drop down text?
I'd like to be able to verify the menu has all the proper dropdown menus with out clicking/selecting, just verifying the id/string of each menu item is ok, I saw from here Selenium: How to select an option from a select menu? how I can select them, but I don't want to开发者_如何学编程 select them. Thanks for any help.
I think you could do something like this to verify the element on the page without selecting them, you're xpath would probably vary my example is quite simplified:
HTML:
<body>
<select>
<option>One</option>
<option>Two</option>
<option>Three</option>
<option>Four</option>
</select>
</body>
Selenium Test Case:
public class HomePageTest {
public static HtmlUnitDriver driver;
@Before
public void setUp() throws Exception {
driver = new HtmlUnitDriver();
}
@Test
public void initiateTest() throws Exception {
driver.get("http://localhost/test3.html");
List<WebElement> elems = driver.findElementsByXPath("//option");
for (WebElement e : elems)
{
System.out.println(e.getText());
}
}
@After
public void tearDown() throws Exception {
driver.close();
} }
精彩评论