I am trying to dynamically select items from a drop down menu based on input. This isn't really a problem unless values share a name. For instance if this is my Cucumber statement
When I go to the "Inventory" / "Inventory" application
When I call this method:
@When("^I go to the \"([^\"]*)\" / \"([^\"]*)\" application$")
public void i_go_to_the_application(String hoverMenu, String subMenuName) throws Throwable {
Actions actions = new Actions(driver);
WebElement menuHoverLink = driver.findElement(By.linkText(hoverMenu));
actions.moveToElement(menuHoverLink);
Thread.sleep(1000);
WebElement submenu = driver.findElement(By.xpath("//span[.='" + subMenuName + "']"));
actions.moveToElement(submenu);
actions.click().perform();
Thread.sleep(4000);
My test crash because it cannot find the subMenuElement. This code works swimmingly if the menu names are different such as Inventory > Items.
Now I've already checked this question Selenium: handling multiple inputs with same xpath
However the solution provide doesn't seem to be helpful since both elements are in the drop down menu with one being a submenu to that one: Inventory > Inventory
I ran this through the selenium IDE and no matter how many ways I've tried to "find" the Inventory element it only ever finds one item. Since the user of my tests can select any number of items from a drop down menu and then subsequent submenus, I can't rely on IDs. Is there a way to select the first menu item for sure and then select the submenu item.