Last active
March 15, 2022 09:54
-
-
Save cmin764/121077463554ceb060716ee847607078 to your computer and use it in GitHub Desktop.
Extends Selenium with user-data option in Chrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from pathlib import Path | |
from RPA.Browser.Selenium import Selenium | |
from SeleniumLibrary.base import keyword | |
from selenium import webdriver | |
from webdrivermanager import ChromeDriverManager | |
class ExtendedSelenium(Selenium): | |
USER_DATA = Path("output") / "Chrome" | |
USER_DATA_PATH = os.getenv("USER_DATA", str(USER_DATA)).strip() | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
cdm = ChromeDriverManager(link_path="AUTO") | |
cdm.download_and_install() | |
@keyword | |
def open_site(self, url, **kwargs): | |
options = webdriver.ChromeOptions() | |
if self.USER_DATA_PATH: | |
options.add_argument(f"user-data-dir={self.USER_DATA_PATH}") | |
self.open_browser( | |
url=url, | |
options=options, | |
**kwargs | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment