Article Overview:
This article will cover how you can achieve the following:
How to resolve the issue of browsers freezing when users attempt to download files.
Problem Statement:
Users often experience browser freezes or hangs when attempting to download files during automated testing, particularly when the download triggers a new tab in the browser. This issue typically occurs due to a Chrome driver bug, where the newly opened tab gets stuck, causing the browser to become unresponsive. Automating such downloads becomes challenging, disrupting the flow of test execution.
This article provides solutions to prevent browsers from freezing during file downloads in Virtuoso by modifying the behaviour of download links and offering methods to handle new tab scenarios efficiently.
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.
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.