1

I'm trying to click on Calendar but everytime I try to click on the calendar the error pop up as "element click intercepted: Element is not clickable at point (293, 1317)

<input type="text" name="form_fields[travel_comp_date]" id="form-field-travel_comp_date"
class="elementor-field elementor-size-sm elementor-field-textual elementor-date-field
flatpickr-input" placeholder="Date of travel"
pattern="[0-9]{4}-[0-9]{2}-[0-9]{2}" readonly="readonly">

Here's my code:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='form_fields[travel_comp_date]']")));
    driver.findElement(By.xpath("//input[@name='form_fields[travel_comp_date]']")).click();  

Can someone please help me correcting this.

4
  • Without seeing that page itself and all your code flow before the piece you shared we can't know what happens there Commented Sep 12, 2022 at 7:23
  • I'm working on this "path2usa.com/travel-companion" there is a calendar in the page itself. I'm trying to click on that but unable to as selenium is throwing error. Commented Sep 12, 2022 at 7:25
  • OK. What do you do after opening that page before trying to click that element? Commented Sep 12, 2022 at 7:28
  • Nothing, I just search for the element by using driver.findelement and then try to click it. Commented Sep 12, 2022 at 7:31

2 Answers 2

1

Please try the following code with explicit wait and let me know if it works for you:

enter code here
driver.get("https://www.path2usa.com/travel-companion/");
WebElement dateTravel =  
driver.findElement(By.xpath("//input[@id='form-field- 
travel_comp_date']"));
driver.manage().window().maximize();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,1000)");
WebDriverWait wait = new WebDriverWait(driver, 
Duration.ofSeconds(5));
js.executeScript("arguments[0].scrollIntoView();", dateTravel);
wait.until(ExpectedConditions.visibilityOf(dateTravel));
if(dateTravel.isDisplayed()) 
  {
    js.executeScript("document.getElementById('form-field- 
travel_comp_date').value='12/20/2023'");
  }

    
Sign up to request clarification or add additional context in comments.

Comments

1

The element you are trying to access is out of the initially presented view port.
In order to click it you first need to scroll the page to bring that element into the visible view port and only after that you will be able to click on it.
Please try this:

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollTo(0, document.body.scrollHeight)");

Or this

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,600)");

After that try performing your code

9 Comments

It is still not working. Still getting the same error.
Does my code perform scrolling and the element becomes actually visible before you clicking on it?
after the scrolling try adding some sleep of maybe a second before performing the click. let me know if that helped
Great! I'm happy I could help you :)
It's okay. Please take your time. I have been trying to do it for so long time but couldn't figure it out.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.