I'm trying to launch Safari with Selenium in python with all my sessions logged in (e.g. gmail) so I don't have to login manually.
The easy solution would be to launch safari with the default user profile, but I can't find documentation on how to do this.
from selenium import webdriver
driver = webdriver.Safari()
url = 'https://www.gmail.com/'
driver.get(url)
Just for reference, the code below is the code for Chrome. What is the safari equivalent?
options.add_argument("user-data-dir=/Users/alexiseggermont/Library/Application Support/Google/Chrome/Default/") #Path to your chrome profile
driver = webdriver.Chrome(chrome_options=options)
driver.get(url)
There is setDataDir()
function in SafariOptions on safari driver v2.43.1 according to document as following however I couldn't find any document about how to use it and there is no information about last versions:
* @param dataDir A File object pointing to the Safari installation's data directory.
* If {@code null}, the default installation location for the current platform will be used.
public void setDataDir(File dataDir) {
this.dataDir = Optional.fromNullable(dataDir);
}
From what I have read, Safari does not have user profiles. If you mean to start Safari from a different Mac user I would suggest doing it with bash:
sudo -u username python open.py
where username
is the username of the user and open.py
is your python file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With