简体   繁体   English

无法通过Selenium和Java在Make My Trip网站中找到返回日期日历中的任何日期

[英]Unable to locate any date from return date calendar in Make My Trip website through selenium and Java

Here i am trying to select return date 12 of April month. 在这里,我试图选择4月的返回日期12月。 i tried with different customized xpath and css but unable to locate the element: 我尝试使用其他自定义的xpath和CSS,但无法找到该元素:

    import java.util.List;
    import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.By;
    import org.openqa.selenium.JavascriptExecutor;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;

public class Make_my_trip {

    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "F:\\Selenium\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("https://www.makemytrip.com/");

        // Selecting Return date
        driver.findElement(By.id("hp-widget__return")).click();
        //WebDriverWait ws = new WebDriverWait(driver, 10);
        //ws.until(ExpectedConditions.presenceOfElementLocated(By.id("dp1551508380301")));
        Thread.sleep(2000);;
        while (!driver.findElement(By.xpath("//span[@class ='ui-datepicker-month']")).getText().contains("April")) {

            System.out.println("Return date selected ");
            driver.findElement(By.xpath(
                    "div[@id='dp1551508898872']//span[@class='ui-icon ui-icon-circle-triangle-e'][contains(text(),'Next')"))
                    .click();
        }

        List<WebElement> returndate = driver.findElements(By.xpath("//a[@class ='ui-state-default']"));
        int count = returndate.size();

        for (int j = 0; j < count; j++) {
            String returndatetext = driver.findElements(By.xpath("//a[@class ='ui-state-default']")).get(i).getText();
            if (returndatetext.equalsIgnoreCase("12")) {
                driver.findElements(By.xpath("//a[@class ='ui-state-default']")).get(i).click();
                break;
            }
        }

    }

PS : PS:

  1. If we use explicitly wait getting " org.openqa.selenium.InvalidSelectorException " Error so as of now use Thread.sleep(1000) . 如果我们明确使用等待得到“ org.openqa.selenium.InvalidSelectorException ”错误,那么从现在开始使用Thread.sleep(1000)
  2. If we use Xpath //div[@class='ui-datepicker-group ui-datepicker-group-last']/div/a/span[contains(text(),'Next' )][1] getting org.openqa.selenium.ElementNotVisibleException: element not visible 如果我们使用Xpath //div[@class='ui-datepicker-group ui-datepicker-group-last']/div/a/span[contains(text(),'Next' )][1]获取组织。 openqa.selenium.ElementNotVisibleException:元素不可见

"Element not visible". “元素不可见”。 I had this error too. 我也有这个错误。 It's mean your searchable element isn't visible in the current snapshot. 这意味着您的可搜索元素在当前快照中不可见。 You should focus on that element or scroll down till element appear in the snapshot 您应该专注于该元素或向下滚动直到该元素出现在快照中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM