如何处理硒中“出发”框和“返回”框的日历?

时间:2019-04-04 08:36:04

标签: selenium selenium-webdriver

如何处理硒中出库和退库的日历。 请检查我的代码一次 网站:https://www.goibibo.com/

public class goibibo {
    private static WebDriver driver = null;
    public static void main(String[] args) throws InterruptedException  {
        // TODO Auto-generated method stub
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.goibibo.com/");
        driver.manage().window().maximize();
        new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='gosuggest_inputSrc']"))).sendKeys("A");
        Thread.sleep(1000);
        List<WebElement> myList = new WebDriverWait(driver, 20).until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//div[@class='dib marginL10 pad0 textOverflow width90']/div/span")));
        for (int i = 0; i < myList.size(); i++)
        {
                System.out.println(myList.get(i).getText());
                if (myList.get(i).getText().equals("Ahmedabad"))
                {
                    myList.get(i).click();
                    break;
                }
            }
        new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"gosuggest_inputDest\"]"))).sendKeys("Mum");
        Thread.sleep(1000);
        List<WebElement> Dept = new WebDriverWait(driver, 20).until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//div[@class='dib marginL10 pad0 textOverflow width90']/div/span")));
        for (int j = 0; j < Dept.size(); j++)
        {
                System.out.println(Dept.get(j).getText());
                if (Dept.get(j).getText().equals("Mumbai"))
                {
                    Dept.get(j).click();
                    break;
                }
        }

        //Thread.sleep(3000);
        //driver.switchTo().frame("notification-frame-~2514428c7");
        //driver.findElement(By.xpath("//i[@class='wewidgeticon we_close']")).click();
        //pop-up frame
        WebDriverWait wait = new WebDriverWait(driver, 5);
        wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[starts-with(@name ,'notification-frame-')]")));
        WebElement element=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//i[contains(@class ,'wewidgeticon')]")));
        element.click();

        //dates
        Thread.sleep(5000);
        driver.findElement(By.xpath("//*[@id=\"searchWidgetCommon\"]/div[1]/div[1]/div[1]/div/div[6]/input")).click();

        List<WebElement> allDates=driver.findElements(By.xpath("//*[@id=\"searchWidgetCommon\"]/div[1]/div[1]/div[1]/div/div[6]/div/div"));

        for(WebElement ele:allDates)
        {

            String date=ele.getText();

            if(date.equalsIgnoreCase("28"))
            {
                ele.click();
                break;
            }

        }

    }

}
  

线程“主”中的异常   org.openqa.selenium.NoSuchElementException:没有这样的元素:无法   定位元素:   {“方法”:“ xpath”,“选择器”:“ // * [@ id =” searchWidgetCommon“] / div [1] / div [1] / div [1] / div / div [6] / input” }

0 个答案:

没有答案