0

In Java web application there's a line of code which opens a popup window whenever clicking on a link and this window has ok/cancle button:

return window.showModalDialog("popupWindow", obj, sFeatures);

I use below code in Selenium to click on the link:

geckoDriver.findElement(By.xpath(".//a[contains(@onclick, 'return openlink(8251')]")).click();

I'm sure the link is clicked successfully but the window.showModalDialog does not open and I can not go on because of that.

What is the problem?

Note that I use GeckoDriver and I also test my application with chromeDriver and ieDriver with no success.

Html tag:

<td width="80" aria-describedby="grdOpeningTrustCartable_" title="openning" style="text-align:center;" role="gridcell">
<a class="gridHighlight" onclick="return openLink(8251,'04/12/17 15:50:00')" href="javascript:void(0);">openning</a>
</td>
1

It's pretty hard to know what the issue is but I'm assuming when you manually click there's no issue. Be sure that when you manually do it you're not double clicking. If you are then it's either a bug or something you need to add into your method.

Another possibility is that sometimes with links the element appears to be a box shape but will only work if the text is clicked. Selenium clicks the top left hand corner of the element by default. I would recommend creating a separate click method and build up the action, adding in moveToElement() which brings the mouse to the centre of the element, that might solve the issue.

For more details see: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/interactions/Actions.html#moveToElement-org.openqa.selenium.WebElement-

  • I'm sure it's not a double click. I'm debugging the main application and I'm sure when I use selenium click method, it reaches the windows.showModalDialog but can not run this code successfully – BzH Apr 12 '17 at 10:37
  • Perhaps there's some javascript interrupting it? Maybe provide the HTML if you can, might be able to spot something there – K-8 Apr 12 '17 at 11:18
  • I posted the Html tag. As I'm debugging the main application, I'm sure the click action is running pretty well but the problem is exactly at line window.showModalDialog – BzH Apr 12 '17 at 16:00
0

It must be due Javascript being executed, while you click on the link. Provide proper wait till javascript execution gets completed and then click on the link, you will surely see the popup.

  • When you have enough reputation, you can add this kind of general guidance as a comment on the question. The OP's question really needs more detail added to provide a good answer, but this is too general to be helpful to future readers or, likely, the OP, as an answer by itself. – c32hedge Mar 12 at 15:50
  • I'm inclined to agree with c32hedge. It's close to an answer but is still quite broad. I'll wait to delete to see if it gets more specific, but for a 2 year old question, it won't be the simplest task. Thanks Sharuya! – corsiKa Mar 12 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.