Selenium打开新的浏览器实例(Brave Browser)

内容来源于 Stack Overflow,遵循 CC BY-SA 4.0 许可协议进行翻译与使用。IT领域专用引擎提供翻译支持

腾讯云小微IT领域专用引擎提供翻译支持

原文
Stack Overflow用户 提问于2020-11-16

我最近开始了一个python自动化项目,它可以检查星期几,如果是工作日,它应该打开一个浏览器,例如,如果是我的大学日程表,如果是周末,它应该打开不同的网站。

我使用brave浏览器作为我的默认浏览器,但我想知道,当我运行我的代码而不是没有我所有书签和密码的新实例时,是否可以打开我的常规浏览器配置文件?

提前感谢!

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
import datetime
day = datetime.datetime.now()
dag = day.weekday()
def Testing():
    if dag >= 5:
        return Weekend()
    else:
        return Weekday()
def Weekend():
    options = Options()
    options.add_argument("--window-size=1920,1080")
    ## options.add_argument("/Users/vadim/Library/Application Support/BraveSoftware/Brave-Browser")
    options.binary_location = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'
    driver_path = '/usr/local/bin/chromedriver'
    driver = webdriver.Chrome(options=options, executable_path=driver_path)
    driver.get('https://outlook.live.com/mail/0/inbox')
    Outlook_Aanmelden = driver.find_element_by_xpath('/html/body/header/div/aside/div/nav/ul/li[2]/a')
    Outlook_Aanmelden.click()
    Email_Field = driver.find_element_by_xpath('//*[@id="i0116"]')
    Email_Field.send_keys('@live.com')
    Outlook_Volgende = driver.find_element_by_xpath('//*[@id="idSIButton9"]')
    Outlook_Volgende.click()
    time.sleep(0.5)
    Password_Field = driver.find_element_by_xpath('//*[@id="i0118"]')
    Password_Field.send_keys('pass')
    Password_Field.send_keys(Keys.ENTER)
    Inlog_Outlook = driver.find_element_by_xpath('//*[@id="idSIButton9"]')
    Inlog_Outlook.click()
    driver.execute_script("window.open('https://youtube.com');")
def Weekday():
    options = Options()
    options.add_argument("--window-size=1920,1080")
    ## options.add_argument("/Users/vadim/Library/Application Support/BraveSoftware/Brave-Browser")
    options.binary_location = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'
    driver_path = '/usr/local/bin/chromedriver'
    driver = webdriver.Chrome(options=options, executable_path=driver_path)
    driver.get('https://outlook.live.com/mail/0/inbox')
    Outlook_Aanmelden = driver.find_element_by_xpath('/html/body/header/div/aside/div/nav/ul/li[2]/a')
    Outlook_Aanmelden.click()
    Email_Field = driver.find_element_by_xpath('//*[@id="i0116"]')
    Email_Field.send_keys('@live.com')
    Outlook_Volgende = driver.find_element_by_xpath('//*[@id="idSIButton9"]')
    Outlook_Volgende.click()
    time.sleep(0.5)
    Password_Field = driver.find_element_by_xpath('//*[@id="i0118"]')
    Password_Field.send_keys('pass')
    Password_Field.send_keys(Keys.ENTER)
    Inlog_Outlook = driver.find_element_by_xpath('//*[@id="idSIButton9"]')