0

I am using Selenium to automate a website interaction through ChromeDriver and .NET C#. The website contains a bootstrap modal dialog as seen in the screen shot. Clicking on the company name in each row will download the company profile PDF document (a child browser window will open for the download).

Human interaction with the website works perfectly. Also, if I run $("div.modal-dialog table>tbody>tr>td")[2].firstElementChild.click(); in Chrome's dev tool console, it also downloads the PDF properly.

But running this line of code in Selenium like this (IJavaScriptExecutor)driver).ExecuteScript(@"$(""div.modal-dialog table>tbody>tr>td"")[2].firstElementChild.click();"); will cause the modal dialog to disappear immediately and no PDF is downloaded.

Selenium is able to find the element at $("div.modal-dialog table>tbody>tr>td")[2].firstElementChild, which I tested in the code, so I'm pretty sure.

I think the automation process is clicking in the main window, not on the modal dialog, causing the latter to disappear immediately. But how to switch to a bootstrap modal popup in Selenium?

Or is it some other problem? Any thoughts? This issue is driving me nuts. Thank you very much in advance.

enter image description here

Stack0verflow
  • 1,091
  • 3
  • 17
  • 41
  • 1
    Can you post your Modal Markup & also the markup where the modal invocation happens. The modal closes when we click outside and may be selenium is performing a similar action. If can stop the modal from dismissing when clicked outside, it could solve your issue. https://stackoverflow.com/questions/22207377/disable-click-outside-of-bootstrap-modal-area-to-close-modal – Vidiya Prasanth Pappannan May 05 '22 at 22:11

0 Answers0