Skip to content

Commit

Permalink
Merge pull request #79 from diogokiss/browser-arguments
Browse files Browse the repository at this point in the history
feat: make the arguments to webdriver.Chrome customizable
  • Loading branch information
nateshmbhat committed Sep 3, 2021
2 parents e743b12 + 5b9d92d commit d6ac484
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions webbot/webbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ class Browser:
- List containing all the errors which might have occurred during performing an action like click ,type etc.
"""

def __init__(self, showWindow=True, proxy=None , downloadPath:str=None):
def __init__(self, showWindow=True, proxy=None , downloadPath:str=None, arguments=["--disable-dev-shm-usage","--no-sandbox"]):
options = webdriver.ChromeOptions()
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")

for argument in arguments:
options.add_argument(argument)

if downloadPath is not None and isinstance(downloadPath,str):
absolutePath = os.path.abspath(downloadPath)
if(not os.path.isdir(absolutePath)):
Expand All @@ -49,9 +51,11 @@ def __init__(self, showWindow=True, proxy=None , downloadPath:str=None):
options.add_experimental_option('prefs', {'download.default_directory' : absolutePath})

if proxy is not None and isinstance(proxy, str):
options.add_argument("--proxy-server={}".format(proxy))
# Check if '--proxy-server' has not yet been set
if not any(arg.starts_with("--proxy-server") for arg in arguments):
options.add_argument("--proxy-server={}".format(proxy))

if not showWindow:
if not showWindow and '--headless' not in arguments:
options.headless = True
options.add_argument("--headless")

Expand Down

0 comments on commit d6ac484

Please sign in to comment.