How to handle calendar popup using Selenium WebDriver with Java?
-
How can I select date from a calendar popup like this gender (i.e 24/04/2015 from calendar) using Selenium WebDriver with Java? 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(); } }
-
Answer:
You can click a day by selecting it from its id and then click on it 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: //.... driver.findElement(By.xpath("//div[2]/ul[3]/li[1]/i")).click(); driver.findElement(By.id('a_2015_4_24')).click(); //...
Deepak gupta at Stack Overflow Visit the source
Related Q & A:
- How to add calendar events in other calendar in Android?Best solution by Stack Overflow
- How to call a popup from a link inside another popup?Best solution by stackoverflow.com
- How to add calendar event in Yahoo calendar?Best solution by Stack Overflow
- How can I run all my selenium tests sequentially in C#?Best solution by Stack Overflow
- How to handle exception in Java?Best solution by javatpoint.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.