因此,我尝试使用if语句来了解如何动态设置selenium使用的变量的路径。主要问题是我希望语句查看驱动程序是否已安装,然后根据platform
模块的platform.system()
函数检查驱动程序是否未安装。我有以下内容,但是我遇到了一个无效的语法问题。我在windows和Linux系统上安装了这些路径,因此我知道它们可以工作
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")
当我尝试在Linux或Windows中调出站点时,会出现以下语法错误:
File "secret_collegeboard_tsi_export.py", line 56
if system = ('Windows'):
^
SyntaxError: invalid syntax
我其实很快就明白了。我使用了以下内容,这与@Muzzamil和@testfile提到的内容类似:
=用于为
variable
赋值。对于equality
检查string
使用或
改用这个:
=是赋值运算符 ==是比较运算符
相关问题 更多 >
编程相关推荐