欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

selenium登录实验楼

程序员文章站 2022-07-04 22:49:59
```Python from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait from se... ......
from selenium import webdriver
from selenium.webdriver.common.by import by
from selenium.webdriver.support.wait import webdriverwait
from selenium.webdriver.support import expected_conditions as ec

username = '' # 输入账号
password = '' # 输入密码

driver = webdriver.chrome()
driver.maximize_window()
wait = webdriverwait(driver, 10)
driver.get('https://www.shiyanlou.com')

# 登录入口
wait.until(ec.element_to_be_clickable((by.css_selector, '#__layout > div > div.body > div.home > div > div.container > div.row > div > div.home-header > div > div > li.nav-item.base-nav-item.sign-in-btn > a'))).click()
# 输入账号密码
wait.until(ec.presence_of_element_located((by.css_selector, '#__bvid__364'))).send_keys(username)
wait.until(ec.presence_of_element_located((by.css_selector, '#__bvid__365'))).send_keys(password)
# 勾选自动登录
wait.until(ec.presence_of_element_located((by.css_selector, '#sign-modal___bv_modal_body_ > div:nth-child(3) > form > div.remember > div > label'))).click()
# 点击登录按钮
wait.until(ec.element_to_be_clickable((by.css_selector, '#sign-modal___bv_modal_body_ > div:nth-child(3) > form > button'))).click()