某运营商运维小白,偶尔值班签收工单,写个脚本减轻工作量
#!/usr/bin/python3.5
from selenium import webdriver
from time import sleep
from selenium.webdriver.chrome.options import Options
def main():
flag = 0
global driver #针对谷歌 在变量名称前加个global声明下这是全局变量dr,或者把dr的定义像代码1那样定义到方法体的外面相当于全局变量。chromedriver不会回收
chrome_options = Options()
chrome_options.add_experimental_option("detach", True) #保持打开
chrome_driver = 'chromedriver' #chromedriver的文件位置
driver = webdriver.Chrome(executable_path = chrome_driver,options = chrome_options)
driver.get('网址')
driver.maximize_window()
sleep(1)
driver.find_element_by_xpath("//*[@id='userName']").send_keys("账户")
driver.find_element_by_xpath("//*[@id='password']").send_keys("密码")
driver.find_element_by_xpath("//*[@id='loginBtn']/img").click() #点击登录
#driver.get('