this code is working properly, but I am thinking of using the design pattern instead of using too many IFs
public void filterByCategory(String filterCategory, String filterMainSubCategory, String filterSubCategory) throws InterruptedException {
actions = new Actions(driver);
for (WebElement mainCategory : mainCategories) {
if (mainCategory.getAttribute("class").equals("accordion") && getText(mainCategory).equals(filterCategory)) {
clickButton(mainCategory);
Thread.sleep(3000);
for (WebElement mainSubCategory : mainSubCategories) {
if (mainSubCategory.getAttribute("class").equals("accordion")
&& getText(mainSubCategory).equals(filterMainSubCategory)) {
clickButton(mainSubCategory);
Thread.sleep(3000);
for (WebElement subCategory : subCategories) {
if (getText(subCategory).equals(filterSubCategory)) {
actions.moveToElement(subCategory).click(subCategory).build().perform();
clickButton(applyBtn);
break;
}
}
} else {
for (WebElement mainSubCategory2 : mainSubCategories2) {
if (getText(mainSubCategory2).equals(filterMainSubCategory)) {
actions.moveToElement(mainSubCategory2).click(mainSubCategory2).build().perform();
clickButton(applyBtn);
break;
}
}
}
}
break;
} else if (getText(mainCategory).equals(filterCategory)) {
WebElement cat = mainCategory.findElement(By.tagName("div"));
actions.moveToElement(cat).doubleClick(cat).build().perform();
Thread.sleep(5000);
clickButton(applyBtn);
break;
}
}
}
Aucun commentaire:
Enregistrer un commentaire