Find_Elements.py 1.37 KB
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())