开发者

Selenium: How to verify menu drop down text?

开发者 https://www.devze.com 2023-04-04 01:14 出处:网络
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

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();
} }
0

精彩评论

暂无评论...
验证码 换一张
取 消