简体   繁体   English

我试图从日历中选择下个月,但无法这样做

[英]I was trying to select the next month from the calendar and was unable to do so

This is the code which I was trying to execute. 这是我试图执行的代码。

driver.get("https://easemytrip.com/");
driver.findElement(By.id("ddate")).click(); 
driver.findElement(By.id("img2")).click();

I am unable to click on the next month of the calendar. 我无法点击日历的下个月。 Here is the HTML code. 这是HTML代码。

 <div class="month"> <div id="dvprevious" class="dvnxt" runat="server"> <img id="img2" onclick="return FillcalendarV(03,2017);" alt="Arrow" src="img/left.png"/> </div> <div class="month2">Apr 2017</div> <div class="month3"> <img id="img1" onclick="return FillcalendarV(05,2017);" alt="Arrow" src="img/right.png"/> </div> </div> 

My two work arounds were to force a mouse click on the item location. 我的两种解决方法是强迫鼠标单击项目位置。

WebElement elem = driver.findElement(By.id("id"));
    Actions action = new Actions(driver);
    action.moveToElement(elem).perform();
    action.moveToElement(elem).click().perform();

or 要么

driver.findElement(By.id("id")).sendKeys(Keys.ENTER);

The problem is that it takes a second for the calendar popup to get rendered so you need a brief pause. 问题在于日历弹出窗口要花一秒钟的时间,因此您需要短暂的停顿。 The next problem I ran into is that you apparently can't click the > img because it's blocked by the container DIV. 我遇到的下一个问题是您显然无法单击> img,因为它已被容器DIV阻止。 So, I just clicked the container DIV and it worked. 因此,我只单击了容器DIV,它就起作用了。 The code below works. 下面的代码有效。

driver.get("https://easemytrip.com/");
driver.findElement(By.id("ddate")).click();
new WebDriverWait(driver, 3).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.month3"))).click();

Following code will work. 以下代码将起作用。

    WebElement ele1 = driver.findElement(By.id("dvfarecal"));
    ele1.click();

    WebDriverWait wait = new WebDriverWait(driver, 5);
    WebElement ele2 = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//img[@src='img/right.png']")));

    ele2.click();
    driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

    WebElement date = driver.findElement(By.id("snd_3_10/05/2017"));
    date.click();

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

相关问题 如何在Java中将日历增加7天直到下个月,然后从Java的开始日期开始增加一年? - How do I increment calendar by 7 days until next month, then year from a starting date in Java? 日历获取下个月 - Calendar Get Next Month 我正在尝试使用 Java 做一个日历程序,但是当它打印时,月初是错误的,它弄乱了输出 - I'm trying to do a calendar program using Java but when it prints, the start of month is wrong and it messed up the output 如何格式化从用户获得的日期作为输入,然后在日历中找到该日期以找出该日历中的day_of_month? - how do i format date that i get from user as input and then find that date in a calendar to find out which day_of_month is it in that calendar? 我试图使用selenium web驱动程序滚动handson表但无法这样做 - I am trying to scroll handson table using selenium web driver but unable to do so 如何在控制台中打印出日历月? - How do I print out a calendar month in console? 为什么用Java日历解析时会出现错误的月份 - why do I get wrong month when parsing with java calendar 如何使用Java日历获取每月的第一天? - How do i get the first day of the month by using java calendar? 如何从日历中获取月份名称? - How can I get Month Name from Calendar? Java日历:如何使用JButton将日历移至下个月? - Java Calendar: How to move calendar to next month using JButton?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM