0

There is a dropdown menu of states on this website (see link below). This is the toughest one I have had to do. Can anyone help me figure out how to select an item from this menu? The problem is that the DOM doesn't change when the list gets populated and so I don't know how to select it.

US Post Office Address Search Page

@FindBy(css = "span.select-current-text") private WebElement state;
public void selectElementByString(WebElement field,  String str ) {     
  state.click();
  // menu appears but doesn't appear in HTML so how do I select?
}

This is how Selenium IDE recorded it:

selenium.click("css=span.select-current-text");
selenium.click("link=RI - Rhode Island");

I suspect the control is created with DOJO Toolkit as seen here .

4

1 回答 1

1

This should work..

    //Name of the state to select.
    String stateName = "AL - Alabama";

    //Open Url.
    driver.get("https://tools.usps.com/go/ZipLookupAction!input.action");

    //Click on state select box, which makes the list visible.
    driver.findElement(By.className("select-current-text")).click();

    //Select the state from the list.
    driver.findElement(By.partialLinkText(stateName)).click();
于 2012-07-19T03:53:56.467 回答