尝试点击出发按钮,但由于元素不可点击而显示错误。谁能建议一种不需要硬编码就可以选择当前日期的方法?
System.setProperty("webdriver.chrome.driver", "C:\Users\rutsahoo\Documents\chromedriver.exe" );
WebDriver driver;
String strURL="https://www.makemytrip.com/";
driver= new ChromeDriver();//created object of chrome driver
driver.manage().window().maximize();
driver.get(strURL);
Thread.sleep(4000);
driver.findElement(By.xpath("(//span[@class="lbl_input latoBold appendBottom10"])[1]")).click();
Thread.sleep(4000);
driver.close();
您正在使用的xpath
没有突出显示DOM中的任何元素。首先点击Departure
元素,然后从calendar
中选择。
Imports required for Explicit Waits:
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
driver.get("https://www.makemytrip.com/flights");
WebDriverWait wait = new WebDriverWait(driver,30);
Actions actions1 = new Actions(driver);
// Close the login pop-up
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//p[contains(@class,'login__earn')]")));
WebElement login = driver.findElement(By.xpath("//p[text()='Login or Create Account']"));
actions1.moveToElement(login).click().perform();
// Close the language pop-up
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='langCardClose']"))).click();
// Departure Element
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[@for='departure']"))).click();
// Select the date
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@aria-label='Wed Oct 27 2021']"))).click();