1

When I use the following code for click or double click using Actions class, it seems like mouse click triggers but is not released. Apparently, the button is highlighted, but click doesn't perform completely.

Click Code:

WebElement refreshPreviewButton = driver.findElement(By.xpath("//div[@data-dojo-attach-point='_previewInTabBtn']"));
Actions action = new Actions(driver);
// Approach 1
action.click(refreshPreviewButton).build().perform();

// Approach 2
action.movetoElement(refreshPreviewButton).click().build().perform();

Double Click Code:

WebElement refreshPreviewButton = driver.findElement(By.xpath("//div[@data-dojo-attach-point='_previewInTabBtn']"));
Actions action = new Actions(driver);

// Approach 1
action.doubleClick(refreshPreviewButton).build().perform();

// Approach 2
action.movetoElement(refreshPreviewButton).doubleClick().build().perform();

Working code of other element on the same page:

WebElement previewInTabButton = driver.findElement(By.xpath("//div[@data-dojo-attach-point='_previewInTabBtn']"));
Actions action = new Actions(driver);
action.doubleClick(previewInTabButton);
action.perform();

HTML:

<div class="c3_axnPrvCHR2 c3_rows_nowrap c3_align_center c3_hidden" data-dojo-attach-point="_r2Cont">
   <div class="c3_axnPrvCBtns c3_axnPrvCBtnsL c3_rows_nowrap c3_align_center btn-sgmt-grp btn-group c3_br4 c3_bdr" data-dojo-attach-point="_btnsCont1">
      <div class="btn-sgmt c3_btn btn-icn-sq btn-icn-sq-34" title="preview" data-dojo-attach-point="_previewBtn">
         <svg class="c3i c3i_txt">
            <use class="c3i_u" xlink:href="#zi-eye-inactive"></use>
         </svg>
      </div>
      <div class="c3_bdr_r"></div>
      <div class="btn-sgmt c3_btn btn-icn-sq btn-icn-sq-34" title="code" data-dojo-attach-point="_codeBtn">
         <svg class="c3i c3i_txt">
            <use class="c3i_u" xlink:href="#zi-code"></use>
         </svg>
      </div>
   </div>
   <div class="c3_axnPrvCBtns c3_axnPrvCBtnsR c3_rows_nowrap c3_align_center c3_gpC16" data-dojo-attach-point="_btnsCont2">
      <div class="btn-default-outline2_new btn-sm c3_btn btn-fx" data-dojo-attach-point="_previewInTabBtn">
         <svg class="c3i c3i_txt">
            <use class="c3i_u" xlink:href="#zi-launch"></use>
         </svg>
         <div>Preview in tab</div>
      </div>
      <div class="btn-default-outline2_new btn-sm c3_btn btn-fx" data-dojo-attach-point="_refreshPreviewBtn">
         <div>Preview</div>
      </div>
   </div>
</div>

Edit 1: Added HTML

Edit 2: Added working code of other element on same page

14
  • I faced similar issues. In order to help here we need to see the page you working on (the link) and the Selenium code before the block you shared. Commented Dec 13, 2022 at 15:56
  • Hi @Prophet ! I'm using Page Object Model. The code block I shared is the only code in my method. I've added HTML. I'm sorry I can't attach screenshot of the page. Commented Dec 13, 2022 at 16:06
  • The HTML will not help here. We need to perform actual debugging Commented Dec 13, 2022 at 16:19
  • Could you please share what was the reason when you faced this issue? Commented Dec 13, 2022 at 16:21
  • I'm not sure I remember. Maybe element should be scrolled into the view, add pause and only when the page is stable make this click/double click. By may be more reasons for that. Let me know if that helped Commented Dec 13, 2022 at 16:28

2 Answers 2

1

In case clicking web element with Actions click or double click seems like the element was clicked / touched but the click / double click did not actually performed we can add a sleep like Thread.sleep(2000); before applying the Actions click.
Waiting for element clickability or visibility may not be enough here since Actions click works not exactly as Selenium click works. So Actions click may need the element to be in the visible viewport and clickable and also the page should be is a stable state, not during scrolling or rendering process.
So, generally I'd suggest to apply here to actions: wait for element clickability + additional sleep, like the following:

WebElement useContentButton = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@data-dojo-attach-point='_previewInTabBtn']")));
Thread.sleep(2000);
Actions action = new Actions(driver);
action.doubleClick(useContentButton).build().perform();
Sign up to request clarification or add additional context in comments.

Comments

0

For anyone who is having a similar issue:

I had to add wait before performing action.

Thread.sleep(2000);
Actions action = new Actions(driver);
action.doubleClick(useContentButton).build().perform();

I got this trick from hover over each stars and then finally click on 4th star.

Comments

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.