About Article:
This article will cover how to resolve the issue of browsers freezing when users attempt to download files.
Description:
When a user tries to download a file (like a PDF) by clicking a link, the browser sometimes hangs and stops working.
This problem occurs because the file download triggers a new tab to open.
This is due to a Chrome driver issue, where the new tab gets stuck, causing the browser to hang.
Solution 1: Modify Links to Prevent Opening New Tabs
If the download link is within an <a href> element, you can prevent it from opening in a new tab by following these steps:
Use the following inline Extension to remove the attribute that opens the link in a new tab.
Execute "[...document.querySelectorAll('a[target=\"_blank\"]')].forEach(e=>e.removeAttribute('target'))"
Explanation:
This expression selects all anchor elements (<a> tags) in the document that have a target attribute set to "_blank" (which typically opens links in a new tab) and removes the target attribute from each of those elements.
In simpler terms, it prevents links with target="_blank" from opening in new tabs.
How to use the Inline Extension:
1. Add the above inline extension before the download test step, this will prevent you from opening the new tab.
Solution 2: Prevent Automatic Switching to New Tabs
Option 1: Use Mouse click instead of a standard click.
Option 2: Alternatively, use JavaScript to perform the click by storing the element details and use the selectors to perform the click if the Mouse click doesn’t work.
Note: Even after following the above options if a new tab is opened, to facilitate smooth tab switching back to the primary tab (AUT), choose index-based tab switching over using the previous or next tab options.
Refer to the valid syntax below for switching tabs using the index:
switch to previous tab
switch to next tab
switch tab to 0
switch to tab 3
Comments
0 comments
Please sign in to leave a comment.