Find_Elements.py
1.37 KB
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
47
48
49
50
51
52
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from time import sleep,ctime
driver = webdriver.Firefox()
driver.maximize_window()
driver.get("https://dengta.vchangyi.com")
# 登录
# driver.find_element_by_xpath("//input[@name='mobile']").send_keys('17321009308')
# driver.find_element_by_xpath("//input[@name='password']").send_keys('123456')
# 显式等待
mobile = WebDriverWait(driver,10,0.5).until(EC.presence_of_element_located((By.NAME,"mobile")))
mobile.send_keys('17321009308')
# 隐式等待
driver.implicitly_wait(5)
try:
print(ctime())
driver.find_element_by_name("password").send_keys('123456')
driver.find_element_by_xpath("//button").click()
# 员工管理
driver.find_element_by_link_text("员工管理").click()
# 岗位管理
driver.find_element_by_link_text("岗位管理").click()
# 操作滚动条,滚动条距离顶部10000个像素点
driver.execute_script("window.scrollBy(0,10000)")
sleep(2)
# 点击保存按钮
#driver.find_element_by_xpath("//button").click()
# alert = driver.switch_to_alert()
# alert.accept()
except NoSuchElementException as msg:
print(msg)
finally:
print(ctime())