0

I am trying to select 2 Jan 2020 in calendar but i am not able to select past month with future year.

For example current month is February. I can easily select any month after February .

This is working with upcoming month's but this code is not working with past months if i am giving future year then January is not selected

//-SCHEDULING SECTION 
            if ("Required".equals(regType)) {
                String dayValue;
                String dd = "";
                String mm = "";
                String yyyy = "";
                String hhMM = "";
                if (dueDate != null && dueDate.trim().length() > 0 && dueDate.contains("Days")) {
                    if (dueDate.contains(" ")) {
                        String[] day = dueDate.split(" ");
                        dayValue =day[0];
                        isDisplayed(numDaysRadioLocator, 10);
                        click(numDaysRadioLocator);

                        Select sel=new Select(driver.findElement(By.id("rvDaysFromSelect")));
                        sel.selectByValue(dayValue);

                        isDisplayed(schedulingContinueButton, 10);
                        click(schedulingContinueButton);
                    } else {
                        System.out.println("Date format not as per requirement so we proceeding  without due date");
                        isDisplayed(schedulingContinueButton, 10);
                        click(schedulingContinueButton);
                    }
                } else if (dueDate.equals("None")) {
                    System.out.println("\t" +  "\t" + "No due date");
                    isDisplayed(schedulingContinueButton, 10);
                    click(schedulingContinueButton);
                } else if (dueDate != null && dueDate.trim().length() > 0 && dueDate.contains("/")) {
                    String[] calendarData = dueDate.split("/");
                    mm = calendarData[0];
                    dd = calendarData[1];
                    yyyy = calendarData[2];
                    hhMM =calendarData[3];

                    isDisplayed(selectSpecificDate,10);
                    click(selectSpecificDate);

                    isDisplayed(dueDateCalendarIcon,10);
                    click(dueDateCalendarIcon);
                    Actions action = new Actions(driver);                   
                    //-Second we are selecting year from calendar
                    new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//div[@class='xdsoft_datetimepicker xdsoft_noselect xdsoft_']//div[@class='xdsoft_label xdsoft_year'])[" + calendarDivNo +"]")));
                    driver.findElement(By.xpath("(//div[@class='xdsoft_datetimepicker xdsoft_noselect xdsoft_']//div[@class='xdsoft_label xdsoft_year'])[" + calendarDivNo +"]")).click();
                    WebElement waitForYearVisibility = driver.findElement(By.xpath("(//div[@class='xdsoft_select xdsoft_yearselect xdsoft_scroller_box']//div[contains(text(),'" + yyyy +"')])[" + calendarDivNo +"]"));
                    action.moveToElement(waitForYearVisibility).build().perform();
                    new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//div[@class='xdsoft_select xdsoft_yearselect xdsoft_scroller_box']//div[contains(text(),'" + yyyy +"')])[" + calendarDivNo +"]")));
                    driver.findElement(By.xpath("(//div[@class='xdsoft_select xdsoft_yearselect xdsoft_scroller_box']//div[contains(text(),'" + yyyy +"')])[" + calendarDivNo +"]")).click(); 

                    //-First we are selecting month from calendar
                    new WebDriverWait(driver, 25).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//div[@class='xdsoft_datepicker active']//div[@class='xdsoft_label xdsoft_month'])[" + calendarDivNo +"]")));
                    driver.findElement(By.xpath("(//div[@class='xdsoft_datepicker active']//div[@class='xdsoft_label xdsoft_month'])[" + calendarDivNo +"]")).click();

                    WebElement waitForMonthVisibility = driver.findElement(By.xpath("(//div[@class='xdsoft_select xdsoft_monthselect xdsoft_scroller_box']//div[contains(text(),'" + mm +"')])[" + calendarDivNo +"]"));
                    action.moveToElement(waitForMonthVisibility).build().perform();
                    new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//div[@class='xdsoft_select xdsoft_monthselect xdsoft_scroller_box']//div[contains(text(),'" + mm +"')])[" + calendarDivNo +"]")));
                    driver.findElement(By.xpath("(//div[@class='xdsoft_select xdsoft_monthselect xdsoft_scroller_box']//div[contains(text(),'" + mm +"')])[" + calendarDivNo +"]")).click();
                    //-Third we are selecting day from calendar
                    List<WebElement> allDays=driver.findElements(By.xpath("//div[@class='xdsoft_calendar']/table//tbody//tr//td"));
                    for(WebElement ele:allDays) {   
                        String date=ele.getText();
                        if(date.equalsIgnoreCase(dd)){ 
                            action.click(ele).build().perform();
                            break;
                        }
                    }
                    //-Finally we are selecting time from calendar
                    Thread.sleep(3000);
                    WebElement waitForTimeVisbibility = driver.findElement(By.xpath("(//div[@class='xdsoft_time_box xdsoft_scroller_box']//div[@class='xdsoft_time_variant']/div[contains(text(),'" + hhMM +"')])[" + calendarDivNo +"]"));
                    action.moveToElement(waitForTimeVisbibility).build().perform();
                    new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//div[@class='xdsoft_time_box xdsoft_scroller_box']//div[@class='xdsoft_time_variant']/div[contains(text(),'" + hhMM +"')])[" + calendarDivNo +"]")));
                    driver.findElement(By.xpath("(//div[@class='xdsoft_time_box xdsoft_scroller_box']//div[@class='xdsoft_time_variant']/div[contains(text(),'" + hhMM +"')])[" + calendarDivNo +"]")).click();

                    isDisplayed(schedulingContinueButton, 10);
                    click(schedulingContinueButton);
                } else {
                    System.out.println("Date format not as per requirement so we proceeding  without due date");
                    isDisplayed(schedulingContinueButton, 10);
                    click(schedulingContinueButton);
                }
            }
Patrick
  • 5,526
  • 14
  • 64
  • 101
Tarun Dabbs
  • 67
  • 13
  • What exception are you getting? – Pradeep hebbar Feb 13 '18 at 16:06
  • @Pradeephebbar This is a exception org.openqa.selenium.WebDriverException: unknown error: Element
    ...
    is not clickable at point (481, 307). Other element would receive the click: ... (Session info: chrome=63.0.3239.132) (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 78 milliseconds Bu
    – Tarun Dabbs Feb 13 '18 at 16:17
  • Can you post your click method – Pradeep hebbar Feb 13 '18 at 16:22
  • @Pradeephebbar This is a code Please check above shared code after this line //-First we are selecting month from calendar First i am clicking on month then after i am trying to scroll till given month – Tarun Dabbs Feb 13 '18 at 16:25
  • @Pradeephebbar First i need to scroll in list because value is dynamic i am trying to scroll in month drop down WebElement waitForMonthVisibility = driver.findElement(By.xpath("(//div[@class='xdsoft_select xdsoft_monthselect xdsoft_scroller_box']//div[contains(text(),'" + mm +"')])[" + calendarDivNo +"]")); action.moveToElement(waitForMonthVisibility).build().perform(); – Tarun Dabbs Feb 13 '18 at 16:28
  • Can you try `JavascriptExecutor ` click once – Pradeep hebbar Feb 13 '18 at 16:38
  • @Pradeephebbar I have already used JavascriptExecutor and i was getting same error org.openqa.selenium.WebDriverException: unknown error: Element
    ...
    is not clickable at point (481, 307). Other element would receive the click: ... (Session info: chrome=63.0.3239.132) (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 78 milliseconds
    – Tarun Dabbs Feb 13 '18 at 16:40
  • WebDriverWait waitForElement = new WebDriverWait(driver, 10); waitForElement.until(ExpectedConditions.elementToBeClickable(By.id("locator"))); Use this before click – Pradeep hebbar Feb 13 '18 at 16:42
  • @Pradeephebbar Actually problem is when we click on calendar and after when we click on month then current month is visible on top and for viewing passed month we need to scroll manually in calendar view . – Tarun Dabbs Feb 13 '18 at 16:42
  • This might help you https://stackoverflow.com/questions/44912203/selenium-web-driver-java-element-is-not-clickable-at-point-36-72-other-el/44916498 – Pradeep hebbar Feb 13 '18 at 16:44
  • Can you post a link to the page? – JeffC Feb 13 '18 at 16:45
  • @Pradeephebbar Thanks for sharing link but i have tried all steps and every time i am getting same error we don't have id we need to use same xpath shared on above in code org.openqa.selenium.WebDriverException: unknown error: Element
    ...
    is not clickable at point (481, 307). Other element would receive the click: ... (Session info: chrome=63.0.3239.132) (Driver info: chromedriver=2.33.506120
    – Tarun Dabbs Feb 13 '18 at 16:54
  • @JeffC Can you please suggest ? – Tarun Dabbs Feb 13 '18 at 17:50
  • @Pradeephebbar This is DOM elements
    January
    == $0
    February
    March
    When we click on calendar then February is highlighted on top in month scroll bar
    – Tarun Dabbs Feb 13 '18 at 18:10
  • Can you please post the website url – Pradeep hebbar Feb 13 '18 at 18:12
  • @pradeephebbar please ignore last share website we are working on staging website and we can't access staging website outside the office – Tarun Dabbs Feb 13 '18 at 18:26
  • /Where should i navigate to see the calendar? – Pradeep hebbar Feb 13 '18 at 18:29
  • Possible duplicate of [Selenium Web Driver & Java. Element is not clickable at point (36, 72). Other element would receive the click:](https://stackoverflow.com/questions/44912203/selenium-web-driver-java-element-is-not-clickable-at-point-36-72-other-el) – undetected Selenium Feb 13 '18 at 20:58
  • @DebanjanB please see in my xpath I am always picking unique value.. – Tarun Dabbs Feb 14 '18 at 07:00
  • @Pradeephebbar Any update on this? – Tarun Dabbs Feb 14 '18 at 11:48
  • I have updated my answer , please have a look – Pradeep hebbar Feb 15 '18 at 10:09

2 Answers2

0

I have gone through the calendar locator and i can see two matches for every locator inside the calendar. I believe you are trying to click the first one and its a hidden one so you are getting the WebDriverException: unknown error.

you can try the below two locators and i believe this will help you.

1. (//div[@class='xdsoft_monthpicker']//button[@class='xdsoft_prev'])[2]

You can also identify the locator by using current month like this

2.(//span[text()='February']/parent::div/parent::div/button[@class='xdsoft_prev'])[2]

Here i am identifying the previous month element by using the 'February' text and i order to use it you have replace the 'February' with the current month to identify the previous month.

  1. You can use this locator also and you may need to change the value based on month.You have to click on the month dropdown first.

    (//div[contains(@class,'monthselect xdsoft_scroller_box')]//div[@class='xdsoft_option ' and text()='March'])[2]
    

But i tried my best to frame locator without using index but no luck.

If the count value is changing on each click and every time you need to select last item , then try like this.

public void clickPreviousMonth() {
        Thread.sleep(30000);
        List<WebElement> previuosMonthElements = context.getDriver().findElements(By.xpath("//div[@class='xdsoft_monthpicker']//button[@class='xdsoft_prev']"));
        int index = previuosMonthElements.size();
        String modifiedXpath = "(//div[@class='xdsoft_monthpicker']//button[@class='xdsoft_prev']["+index+"])";
        Thread.sleep(30000);
        context.getDriver().findElement(By.xpath(modifiedXpath)).click();
    }

*I have used the sleep directly , you can try with fluentwait

Hope this will help you.

Pradeep hebbar
  • 2,147
  • 1
  • 9
  • 14
  • Thanks for your reply . I have checked with all above options but my issue not resolved and i am getting same error org.openqa.selenium.WebDriverException: unknown error: Element
    ...
    is not clickable at point (481, 307). . Yes you are right we have 2 calendar in same page if you will see in my shared code my xpath is dynamic and my code is working fine with current and future months . I have facing issue only with Passed month .
    – Tarun Dabbs Feb 15 '18 at 09:54
  • Can you please suggest me is there any way to scroll month drop down till top position . Because if we will scroll up to maximum then this will work. – Tarun Dabbs Feb 15 '18 at 10:37
  • As per my execution or client requirement we need to read month name from excel sheet . Suppose Currently April month is running and client send January in excel sheet and in this condition above code will not work because as per above code we are selecting last previous month . Can you please send me a solution like if any month is running and we can easily select any month from past month – Tarun Dabbs Feb 15 '18 at 12:47
0

I have resolved this scenario..

I have change drop down pixel position at the time of execution with Java script.

Now I have set drop down pixel position 0 at run time.

Tarun Dabbs
  • 67
  • 13