[英]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.