2

I have an automation project that requires opening the URL to a Microsoft SharePoint file and performing some action on the website instead of downloading it.

In my excel, if i "click" the hyperlink I can get directly opened up in the browser using the always open file option in chrome.

import pandas as pd
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By

#url that generated from my Excel file containing hyperlink
df = pd.DataFrame(['https://company.sharepoint.com/sites/Test.xlsx', 'https://company.sharepoint.com/sites/Test2.xlsx'])
df.columns = ['url']

options = Options()
driver = webdriver.Chrome(options = options)
for url in df.url:
    driver.get(url)

it just downloads the file instead of opening it in the browser if i code it using Selenium to open these url link

kata1000
  • 60
  • 4

1 Answers1

0

At least in Chrome you should be able to prevent the save file dialog from opening and to specify a download directory.

from selenium import webdriver

options = webdriver.ChromeOptions()
prefs = {
   'download.default_directory': '/tmp',
   'download. prompt_for_download': False,
}

options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(options=options)
doberkofler
  • 9,511
  • 18
  • 74
  • 126
  • Tried many methods and had no luck. I have to reroute my automation flow directly and copy the full link to the website instead of generating it to Excel hyperlink. Thanks anyway! – kata1000 Jun 14 '22 at 15:27