Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97825

How to Make a Path Dynamically Based off System Variable in Python For Selenium

$
0
0

So I am trying to make a if statement to figure out how to dynamically set the path for a variable to be used by selenium. The main thing is I want the statement to look to see if the driver is installed and then break if the driver is not installed based off of the platform.system() function from platform module. I have the following, but I am getting an invalid syntax issue. I have the paths working and installed on a windows and Linux system so I know they work.

import selenium
import shutil
import xlsxwriter
import os
import unittest
import requests
import subprocess
import getpass
import platform
import logging
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from datetime import date

# Definitions
# find_elements_by_name
# find_elements_by_xpath
# find_elements_by_link_text
# find_elements_by_partial_link_text
# find_elements_by_tag_name
# find_elements_by_class_name
# find_elements_by_css_selector

# System Variables
date = today.strftime("%m/%d/%Y")
system = platform.system()
today = date.today()
username = getpass.getuser()

# URL Variables 
login_url = 'https://www.accuplacer.org/'
redirect_url = 'https://www.accuplacer.org/api/home.html#/'
reports_scheduler_url = 'https://www.accuplacer.org/api/home.html#/reportScheduler'
custom_reports_url = 'https://www.accuplacer.org/api/home.html#/customReports'

# WebDriver Path for System
if system = ('Windows'):
      browser = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\chromedriver.exe")
elif system = ('Linux'):
      broswer = webdriver.Chrome("~/Drivers/Google/Chrome/chromedriver_linux64")
elif system = ('Darwin'):
      browser = webdriver("~/Drivers/Google/Chrome/chromedriver_mac64")
else:
      print("Are you sure you have the Selenium Webdriver for Chrome installed in the correct path?")
      continue

# Parent URL
browser.get("https://www.accuplacer.org")

When I try to pull up the site in Linux or Windows I get the following syntax error:

  File "secret_collegeboard_tsi_export.py", line 56
    if system = ('Windows'):
              ^
SyntaxError: invalid syntax


Viewing all articles
Browse latest Browse all 97825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>