# Install Libraries
from selenium import webdriver
from selenium.webdriver.safari import options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.safari.options import Options as SafariOptions
# Login Credentials
username = "user"
password = "pass"
# Webdriver Installation
safari_options = SafariOptions()
#safari_options.add_experimental_option("detach", True)
driver = webdriver.Safari(options=safari_options)
# Open URL
driver.get("https://www.expedia.com/TAAP-Info")
# Enter Login Details & Sign in
# Find Username & Send Username to input field
uname = driver.find_element("id", "emailInput")
uname.send_keys(username)
# Find Password & Send Password to input field
pword = driver.find_element("id", "passwordInput")
pword.send_keys(password)
# Click Sign-In Button
driver.find_element("id", "submitLoginAction").click()
# Wait for page to load
WebDriverWait(driver, 10).until(
lambda x: x.execute_script("return document.readyState === 'complete'")
)
# Verify Login is Successful
error_message = "Invalid username or password. Please try again."
# Retrieve any errors found.
errors = driver.find_elements(By.CLASS_NAME, "flash-error")
# When errors are found, the login will fail.
if any(error_message in e.text for e in errors):
print("[!] Login failed")
else:
print("[+] Login successful")
What am I doing wrong? How do I keep safari open?
I have tried using addexperimentaloptions, but it does not seem to recognize it. What else do I need to add to help run this code and allow for Safari to still stay open?
The detach doesn't seem to work as .add_experimental_options doesn't seem to be valid in safari as opposed to Chrome driver.