下载地址1:ChromeDriver - WebDriver for Chrome - Downloads (梯子)
下载地址2:CNPM Binaries Mirror
a.放进任意(所示)目录,如图配置
3.打开网页
import time
from selenium import webdriver
driver = webdriver.Chrome()
url = "https://www.baidu.com"
driver.get(url)
time.sleep(3)
driver.quit()
测试页面
测试页面——输入框
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
url = r"D://Test\index1.html"
driver.get(url)
# 获取输入框元素
username_input = driver.find_element(By.ID, "username")
password_input = driver.find_element(By.ID, "password")
# 输入用户名和密码
username_input.send_keys("username")
time.sleep(2.5)
password_input.send_keys("password")
time.sleep(2.5)
# 提交表单
driver.find_element(By.ID, "submit").click()
time.sleep(2.5)
# 等待页面加载完成
driver.implicitly_wait(10)
t = driver.title
print(t)
# 断言网页上的文本是否为预期值
assert driver.title == "测试页面"
# 关闭浏览器
driver.quit()
- 未完结-
欢迎您的共同编辑 加入编辑团队 -bluearmy- 486985940