简体   繁体   English

如何使用带有Java的Selenium WebDriver处理日历弹出窗口?

[英]How to handle calendar popup using Selenium WebDriver with Java?

How can I select date from a calendar popup like this gender (ie 24/04/2015 from calendar) using Selenium WebDriver with Java? 如何使用带有Java的Selenium WebDriver从这种性别的日历弹出窗口中选择日期(例如,从日历中的24/04/2015)?

I have tried this: 我已经试过了:

package com.Automation;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class CalendarPopup {

    /**
     * @param args
     */
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.yatra.com/");
        driver.findElement(By.id("//div[2]/ul[3]/li[1]/i")).click();
        driver.findElement(By.id("a_2015_4_25")).click();
    }
}

You can click a day by selecting it from its id and then click on it 您可以通过从一天的ID中选择一天来单击它,然后单击它

driver.findElement(By.id('a_2015_4_24')).click(); //use this format a_yyyy_m_d

you can also go back or forward by clicking the calendar arrows: 您还可以通过点击日历箭头来前进或后退:

driver.findElement(By.className('js_btnNext')).click() // click the "next" arrow
driver.findElement(By.className('js_btnPrev')).click() // click the "prev" arrow

note that you cannot click past days or days that are not visible, also the calendar must be visible when you click the day. 请注意,您不能单击过去的日子或不可见的日子,并且单击日期时日历也必须可见。

EDIT: your are selecting wrongly your elements in your code, as you are selecting an element by id passing an xpath to the function, it should be like this: 编辑:您在代码中错误地选择了元素,因为您通过将xpath传递给函数的id来选择元素,所以应该像这样:

//....
driver.findElement(By.xpath("//div[2]/ul[3]/li[1]/i")).click();
driver.findElement(By.id('a_2015_4_24')).click();
//...

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

相关问题 如何使用Java通过Selenium WebDriver处理fancybox弹出窗口 - How to handle fancybox popup through Selenium WebDriver using Java 如何使用 Java 处理 Selenium WebDriver 的身份验证弹出窗口 - How to handle authentication popup with Selenium WebDriver using Java 如何使用 Java 使用 Selenium WebDriver 在 Chrome 中处理身份验证弹出窗口 - How to handle authentication popup in Chrome with Selenium WebDriver using Java 如何使用Java中的Selenium WebDriver处理身份验证弹出窗口 - How to handle authentication popup with Selenium WebDriver in Java 使用Selenium WebDriver处理日历 - Handle calendar using Selenium WebDriver 如何使用Java处理Selenium Webdriver中的嵌套弹出窗口? - How to handle nested popup windows in selenium webdriver with java? 如何使用 Selenium/Java 处理 WebDriver 中不存在的弹出窗口 window? - How to handle a popup window that does not exist in the WebDriver with Selenium/Java? 如何使用 java 在 Selenium WebDriver 中处理 iframe - How to handle iframe in Selenium WebDriver using java 如何在Selenium WebDriver中使用Java处理灯箱 - How to handle lightbox using java in selenium webdriver 如何使用 Selenium Webdriver 处理浏览器身份验证弹出窗口 - How to Handle Browser Authentication popup using Selenium Webdriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM