0

Such methods as org.openqa.selenium.WebElement.click() or org.openqa.selenium.interactions.Actions.click() don't trigger any errors while running, but also the action of clicking doesn't happen. Tried using Javascript, but the element i'm trying to click appears to be unclickable (returns undefined in developer tools in Chrome)

Here is the html of the element

<div class="flatpickr-calendar animate showTimeInput arrowTop open" tabindex="-1" style="width: 245px; top: 719px; left: 1603.17px; right: auto;">
 <div class="flatpickr-months">...</div>
 <div class="flatpickr-innerContainer">
  <div class="flatpickr-rContainer">
  <div class="flatpickr-weekdays">...</div>
   <div class="flatpickr-days" tabindex="-1" style="width: 245px;">
    <div class="dayContainer">
     <span class="flatpickr-day " aria-label="December 29, 2019" tabindex="-1">29</span>
    </div>
   </div>
  </div>
 </div>
</div>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
user218649
  • 73
  • 1
  • 8

2 Answers2

0

To click on the element you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.dayContainer>span.flatpickr-day[aria-label='December 29, 2019']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='dayContainer']/span[@class='flatpickr-day ' and text()='29']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • The problem is, that there must be an exception if the element is unclickable (cannot be found, blocked by other element, and etc.). But even with the WebDriverWait test runs without any exceptions and doesn't perfrom any click actions with standart clicking methods – user218649 Dec 25 '19 at 03:58
0

Regular executeScript(“arguments[0].click();“, element); will not work in this situation. I had to create a string with some javascript code, which looks something like this

String javaScript = “let elem = arguments[0];” + “function triggerEvent(el, event){”
            + “var clickEvent = new MouseEvent(event,{view:window, bubbles:true, cancelable:true, clientX:20});”
            + “console.log(el.dispatchEvent(clickEvent));” + “el.style.background=‘red’;}”
            + “console.log(triggerEvent(elem, ‘mousedown’));“;
user218649
  • 73
  • 1
  • 8