Я пытаюсь выбрать конкретный месяц на веб-сайте spicejet из поля «дата отправления», используя цикл while. Когда наступает конкретный месяц, я выхожу из цикла while и затем выбираю дату из определенного месяца. В приведенном ниже коде я наблюдаю, что цикл while выполняется в бесконечном цикле и не останавливается по достижении определенного месяца.
public class CalendarHandling {
static WebDriver driver;
static By forwardArrow = By
.xpath("//*[local-name()='svg' and @data-testid='svg-img']//*[name()='g' and @transform='translate(1 1)']");
public static void main(String[] args) {
BrowserUtil butil = new BrowserUtil();
driver = butil.launchBrowser("chrome");
butil.launchURL("https://www.spicejet.com/");
selectdepartDate();
}
public static void selectdepartDate() {
//click the departure date
driver.findElement(By.xpath("(//div[@data-testid='departure-date-dropdown-label-test-id']/div/div)[2]")).click();
//store the departure month value
String departMonthValue = driver.findElement(By.xpath(
"//div[contains(@data-testid,'undefined-month')]/child::div/div[contains(normalize-space(),'June')]"))
.getText();
System.out.println(departMonthValue);
//click the forward arrow until departure month is August 2024
while (!departMonthValue.trim().contains("August 2024")) {
driver.findElement(forwardArrow).click();
departMonthValue = driver.findElement(By.xpath(
"//div[contains(@data-testid,'undefined-month')]/child::div/div[contains(normalize-space(),'July')]"))
.getText();
}
//select the date
driver.findElement(By.xpath("//div[contains(@data-testid,'undefined-month')]//div[text()='28']")).click();
}
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... enium-java