What methods are available for managing file download prompts in Safari when using Nightwatch?

Is there a way to customize Safari options similar to Firefox, but I'm having trouble with handling download pop-ups in my test. Any suggestions? Thank you

"safari": {
      "downloadFolder": "Users/chef/Downloads/",
      "desiredCapabilities": {
        "browserName": "Safari",
        'safari:safariOptions': {
          prefs: {
            'safari.options.dataDir':'Users/chef/Downloads/',
            'safari.helperApps.neverAsk.saveToDisk':'image/jpeg;application/binary;application/pdf;text/plain;application/text;text/xml;application/xml;text/html;text/csv;video/mp4'
          },
        }
      }
    }

I came across some related posts that could provide more insight

  • How to handle file download for Selenium WebDriver for Safari
  • How to set Safari download location - Selenium WebDriver

Answer №1

If you are looking to navigate between windows while using Selenium, check out this insightful article that covers various methods: https://example.com/selenium-window-switching

To effectively handle scenarios like dealing with download pop-ups, it is recommended to store the ID of the original window and then utilize the switchTo() method:

//Save the ID of the current window
const originalWindow = await driver.getWindowHandle();

//Ensure no other windows are currently open
assert((await driver.getAllWindowHandles()).length === 1);

//Click on a link that opens in a new window
await driver.findElement(By.linkText('New Window')).click();

//Wait for the new window/tab to appear
await driver.wait(
    async () => (await driver.getAllWindowHandles()).length === 2,
    10000
);

//Switch to the new window handle
const windows = await driver.getAllWindowHandles();
windows.forEach(async handle => {
  if (handle !== originalWindow) {
    await driver.switchTo().window(handle);
  }
});

//Wait for the new tab content to fully load
await driver.wait(until.titleIs('Selenium Docs'), 10000);

For more examples and information, refer to the official Selenium documentation on switching windows or tabs: https://www.selenium.dev/documentation/webdriver/browser_manipulation/#switching-windows-or-tabs.

If you have any questions or need further assistance, feel free to reach out!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

You should only call them after the method that returns a promise has completed

submitTCtoDB() { console.log("The selected file list contains: " + this.selectedFileList) this.readFile().then(() => { alert("ReadFile has finished, now submitting TC"); this.submitTC() }); } readFile() { return new Promise((resolve, r ...

What is the reason for not being able to locate the controller of the necessary directive within AngularJS?

A couple of angularjs directives were written, with one being nested inside the other. Here are the scripts for the directives: module.directive('foo', [ '$log', function($log) { return { restrict: 'E', r ...

The FileReader's onload event handler does not seem to be triggering as expected

In short, my issue revolves around reading a csv file from an android device using JavaScript's FileReader. Although my code was functioning properly a month ago, upon revisiting it recently I discovered that the onload function no longer seems to be ...

Troubleshooting jQuery and CSS problems related to window size discrepancies

My website dynamically calculates the size of each div based on the window size... // Functions to begin $(document).ready(function(){ $('.wrapper').css({'top' : '0px','left' : '0px'}); $(&ap ...

Array Filtering with Redux

I have come across similar queries, but I am still unable to find a solution. While typing in the search box, the items on the screen get filtered accordingly. However, when I delete a character from the search box, it does not show the previous items. For ...

There was an issue loading the file list: `/Target Support Files. npx react-native run-ios`

After upgrading my Mac to macOS Ventura V13 and XCode Version 14.0.1, my React Native projects were running smoothly until today when I encountered errors while trying to start a new project. I have been searching for a solution to this problem for severa ...

Setting the state for individual elements in an array: A step-by-step guide

I'm currently facing an issue with displaying only the first 4 elements from each nested array in an array of arrays on initial render. I have a showMore button that is supposed to reveal the next 4 items from the array when clicked, but it affects al ...

Is there a way to implement a local gltf loader in three.js to display on a GitHub server within my repository?

Every time I run code on my VS app, it works perfectly fine. However, when I try running it on GitHub, it shows an error 404 and gets aborted. I came across some documentation regarding this issue, but I'm having trouble understanding it. Check out ...

How come I am unable to invoke this method again using the same parameters? (null reference error)

I seem to be facing a challenge that I can't quite wrap my head around. I expect this method to return a web element, but in case a specific error occurs, I want it to make another attempt: int findCounter = 0; public IWebElement Find([Optional] stri ...

One method to add up the variances of each pair, and then total the results of each pair using nedb

In my nedb database called trades.json, I am simulating stock trades with the following data: {"buySell":"BUY","currentPrice":431.55,"_id":"GyTaUKVOCa9x5APS"}, {"buySell":"SELL","cu ...

Uncovering data from a dynamic website through the combination of Selenium and PhantomJS

I am attempting to obtain the timer value from this website http://prntscr.com/kcbwd8 located at , and ideally save it in a variable. import urllib from bs4 import BeautifulSoup as bs import time import requests from selenium import webdriver from urllib. ...

Encountering difficulties while trying to include js-search in a Vue.js component

My current challenge involves importing the js-search npm module into a Vue component. However, whenever I attempt to do so using: import JsSearch from 'js-search' The subsequent console.log(JsSearch) statement returns undefined. To further in ...

Difficulty reloading after updating input using AngularJS ngTable

I'm encountering an issue where I need to utilize ngTable with TableParams to load and modify a table. For instance, when the page initializes, entering a number in the textbox for the first time displays the appropriate number of rows in the table. ...

Disabling JavaScript dynamically in Selenium WebDriver for Firefox

While I am aware that Firefox profiles can be used to disable JavaScript, like in this example on Selenium WebDriver, I have come across a scenario where I need JavaScript enabled for logging into a page, but disabled once logged in. This way, when I use ...

Tips for refreshing the modified toggle in angular2

I currently have a newsletter subscription that is initially set based on the newsletter I receive when the user logs in. However, when I toggle the newsletter option, I receive a "successfully updated" message but the newsletter remains set to false even ...

Binding ngModel to a method within $scope in Angular

Not really a question with code, but more for my clarification. Please excuse me if this isn't the appropriate place to ask... I was experimenting with a basic checkbox that had an ngModel assigned to it: <input type="checkbox" ng-model="someFlag ...

Guide on how to use JavaScript to make an HTML5 input field mandatory

I am facing an issue with setting input fields as required based on radio button selection in a form. Initially, all fields should have required=false, but I'm unable to achieve this. No matter what value I assign to the required attribute, it always ...

JavaScript: Exploring Content Inside Headers

Using document.body.innerHTML allows you to search within the body of a webpage. Is there an equivalent method for searching within the "Head" section? I've been looking around but so far, I haven't come across any such function. ...

The C# function encountered an internal server error while being called through a jQuery request

I am having trouble executing a C# function call from jQuery with the code below. I keep receiving an Internal Server Error. Can someone please assist me in identifying the issue and how to resolve it? Thank you. Script <script type="text/javascript"& ...

Initially submitted data in React state fails to update. It takes a second submission for the state to reflect the

I have encountered an issue with setState not being available immediately, as it is pending. Following advice to use arrow functions and console.log, I noticed that the state "desiredIncome" worked correctly, but not "total". The "total" state was only upd ...