Jquery Datepicker

I have the following code  but its not selecting the date:  it is printing the required date but not selecting on the web

 

Default Asked on February 20, 2015 in Selenium WebDriver.
Add Comment
  • 3 Answer(s)

    We cannot understand the issues unless you show us the HTML code of your date picker.

    Thanks
    Virender

    Professor Answered on February 23, 2015.
    Add Comment

    Hi this is the website I am trying to code for Calendar :
    www.rentalcars.com

    I have this code in place

    private void webpickDDate() {
    WebElement webpickupdate = driver.findElement(webpickUpdateLocator);
    webpickupdate.click();
    Calendar cal = Calendar.getInstance();
    WebElement next1 = driver.findElement(By.xpath(“//div[@id=’ui-datepicker-div’]/div/a[2]”));
    next1.click();
    WebElement next2 = driver.findElement(By.xpath(“//div[@id=’ui-datepicker-div’]/div/a[2]”));
    next2.click();
    WebElement next3 = driver.findElement(By.xpath(“//div[@id=’ui-datepicker-div’]/div/a[2]”));
    next3.click();
    cal.add(Calendar.DATE, 1);
    cal.add(Calendar.MONTH, 3);
    DateFormat df = new SimpleDateFormat(“dd/MM/YYYY”);
    for (int i = 0; i <= 7;) {
    int dayofweek = cal.get(Calendar.DAY_OF_WEEK);
    if (dayofweek == Calendar.SUNDAY) {
    cal.add(Calendar.DATE, +1);
    String newdate = df.format(cal.getTime());
    webpickupdate.sendKeys(newdate);
    webpickupdate.click();
    webpickupdate.sendKeys(Keys.RETURN);
    System.out.println(newdate);
    break;
    } else {
    String date = df.format(cal.getTime());
    webpickupdate.isSelected();
    //webpickupdate.isSelected();
    webpickupdate.sendKeys(Keys.RETURN);
    System.out.println(date);
    break;
    }
    }
    }

    Default Answered on February 23, 2015.
    Add Comment

    If we look at the calander the html code is
    <td class=”  ui-datepicker-current-day” onclick=”DP_jQuery.datepicker._selectDay(‘#dp_pu’,1,2015, this);return false;”><a class=”ui-state-default ui-state-active” href=”#”>25</a></td>
    <a class=”ui-state-default ui-state-active” href=”#”>25</a>
    </td>

    The point here is that <a/> tag is the one which should get the click command. in your Calender class you must be doing sending click to the <td/> tag.

    Try reversing the click() on either of the two.

    Also if you analyze the html you will see that the <td> tag has onclick javascript. you can execute the java script your self to select that element.

    DP_jQuery.datepicker._selectDay(‘#dp_pu’,1,2015, this);return false;

    just change the second and third parameter yourself and use the executeJavascrit methos.

    Thanks
    Virender

    Professor Answered on February 23, 2015.

    Hi Virendar ,

    thanks for the reply but the calendar image is a span element it is not allowing to using any click method , how do i resolve this

    on February 24, 2015.

    //span[@id=”dp_pu_img”]

    on February 24, 2015.

    Let me get back to you  from home. I will try to write a small test and share the code.

    Thanks
    Virender

    on February 26, 2015.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.