-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (35 loc) · 1.21 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.common.exceptions import NoSuchElementException
import time
import config
user = config.user
pswd = config.pswd
url = config.url
domain_name = config.domain_name
options = webdriver.FirefoxOptions()
options.add_argument("-headless")
driver = webdriver.Firefox(options=options)
driver.get(url)
time.sleep(1)
try:
driver.find_element(By.XPATH,"//span[text()=' 注销 ']").click()
time.sleep(1)
except NoSuchElementException:
pass
username = driver.find_element(By.XPATH, "//input[@placeholder='请输入用户名']")
wait = WebDriverWait(driver, timeout=20)
wait.until(lambda d : username.is_displayed())
username.clear()
username.send_keys(user)
password = driver.find_element(By.XPATH, "//input[@placeholder='请输入密码']")
password.clear()
password.send_keys(pswd)
driver.find_element(By.XPATH, "//span[@class='el-checkbox__inner']").click()
driver.find_element(By.XPATH, "//span[text()=' 登录 ']").click()
time.sleep(1)
driver.find_element(By.XPATH, f"//span[text()=' {domain_name} ']").click()
time.sleep(1)
wait = WebDriverWait(driver, timeout=20)
driver.quit()