Есть такой вопрос. Есть меню и в меню элементы. Как красиво организовать код для выбора элементов главного меню и суб элементов на selenium?
Мой код:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class MainMenu extends AbstractContainer {
public MainMenu(WebDriver driver) {
super(driver);
}
// name - текст элемента меню
public MainMenu selectMenuItem(String name) {
String menuItemXpath = String.
format("//li[@class='nav']//a[text()='%s']", name);
return clickMenuElement(menuItemXpath);
}
public MainMenu selectSubMenuItem(String name) {
String subMenuItemXpath = String.
format("//li[@class='subnav']//a[text()='%s']", name);
return clickMenuElement(subMenuItemXpath);
}
private MainMenu clickMenuElement(String elementXpath) {
driver.findElement(By.xpath(elementXpath))
.click();
return this;
}
}
Как видите все элементы меню имеют css класс ‘nav’, а суб меню класс ‘submenu’. Можно ли мой код переписать как то более красиво?