记录selenium,python自动化测试中的chromedriver.exe地址和打开后自动关闭浏览器问题
selenium的官方地址为:https://selenium-python.readthedocs.io/index.html
镜像地址:https://npmmirror.com/
# 导入 webdriver
from selenium import webdriver
from selenium.webdriver.common.by import By
# 调用键盘按键操作时需要引入的Keys包
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import time
# url地址
url = 'http://xxxx:9000/login'
# 定义chrome驱动去地址
path = Service('chromedriver.exe')
# 设置属性
options = Options()
# 设置不自动关闭浏览器
options.add_experimental_option('detach', True)
# 创建浏览器操作对象
browser = webdriver.Chrome(service=path, options=options)
# 最大化窗口
browser.maximize_window()
browser.get(url)
user = browser.find_elements(By.CLASS_NAME, 'el-input__inner')[1]
pwd = browser.find_elements(By.CLASS_NAME, 'el-input__inner')[2]
user.send_keys("XXXXXXX")
pwd.send_keys("XXXXXXXX")
login_btn = browser.find_element(By.CLASS_NAME, "el-button--primary")
login_btn.click()
time.sleep(5)
ehr_btn = browser.find_elements(By.CSS_SELECTOR, ".el-menu--horizontal li")
ehr_btn[1].click()
time.sleep(1)
sub_btn = browser.find_elements(By.CLASS_NAME, "el-sub-menu__title")
for item in sub_btn:
if item.text == '考勤管理系统':
item.click()
if item.text == '考勤管理':
item.click()
time.sleep(1)
item_btn = browser.find_elements(By.CSS_SELECTOR, "li.el-menu-item.menuItem")
for itemS in item_btn:
if itemS.get_attribute("textContent").strip() == '出勤档记录查询':
itemS.click()
…………