How to handle a popup in selenium webdriver?

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

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

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.