2

I am trying to use something like this, similar to my firefox options, but my test doesn't seem to handle the download pop-up, 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 found there were exisitng posts that might provide some context

prafful24
  • 57
  • 7

1 Answers1

2

There are some Selenium methods to switch windows, which you can see in this article: https://saucelabs.com/blog/selenium-tips-working-with-multiple-windows

If you were to store the ID of the original window then use the switchTo() method and go to the original window, hopefully you can handle any issues with interacting with the download pop-up:

//Store the ID of the original window
const originalWindow = await driver.getWindowHandle();

//Check we don't have other windows open already
assert((await driver.getAllWindowHandles()).length === 1);

//Click the link which opens in a new window
await driver.findElement(By.linkText('new window')).click();

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

//Loop through until we find a 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 to finish loading content
await driver.wait(until.titleIs('Selenium documentation'), 10000);

See the Selenium Docs for additional examples: https://www.selenium.dev/documentation/webdriver/browser_manipulation/#switching-windows-or-tabs.

Not sure if this helps, let me know!

walkerlj0
  • 101
  • 3
  • This might be the only way to go; Apple has helpfully decided to not provide a list of Safari driver profile options so it's hard to know what controls there are. – Dylan Lacey Nov 25 '21 at 05:27