bringing up calendar picker in input with Selenium/Java

I have to test this date picker using Java and Selenium. See picture. The non yellow-highlighted part is where you put the date text, and the yellow part, when you click on it, brings up a date picker.

My problem is the whole field is just one input, and the only line inside a div:

 <div class="term_dateWidth__hL6-b" style="visibility: visible;">
    <input type="date" id="start" min="1900-01-01" max="9999-12-30" value="">
 </div>

I can find the element but when I click it it only highlights the text box and does not bring up the picker. If I manually click on that highlighted part with the mouse it will bring it up. I just can’t figure out how to do it with Selenium. I even tried the parent div but that did not work.

I though maybe with Actions I could go to a point but that didn’t seem to work either, though maybe I don’t understand using dimensions correctly. Element termDateArrow has already been set to the input below.

public void clickTermDateArrow() {
    Dimension size = termDateArrow.getSize();
    int height = size.getHeight();
    int width = size.getWidth();
    Point point = termDateArrow.getLocation();
    int x = point.getX();
    int y = point.getY();
    Actions action = new Actions(driver);
    action.moveToElement(termDateArrow, width - 1, y + 10).build().perform();
}

but that doesn’t work either. I am trying to click an offset from the top left point (which getLocation() works. And yes I know I can send text to the box but that does not test the picker.

Any suggestions? See image

enter image description here

  • Please, provide a minimal reproducible example

    – 




  • you’ll probably want to use offets with moveToElement when doing the click. So get the element, then use Actions to click it with an offset of 0, +x number of pixels: selenium.dev/selenium/docs/api/java/org/openqa/selenium/… You’ll be starting at the middle of the element… you can get the element’s width with the .getSize() method… offset a little less than half the width. Note that these controls are browser-specific so you may need to branch code per browser.

    – 

Leave a Comment