通过ID查找元素
driver.find_element(By.ID,**'username'**)
//username为id名<br /> driver.find_element(By.ID,**'password'**)
通过id向元素发送文本内容
driver.find_element(By.ID,**'username'**).send_keys(**'21024.admin'**)<br /> driver.find_element(By.ID,**'password'**).send_keys(**'qwer.1234'**)
代码块
登录页面代码:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
#webdriver 获取浏览器的对象
from selenium.webdriver.support.select import Select
d = Service("chromedriver.exe")
driver = webdriver.Chrome(service=d)
# s = Service("chromedriver.exe")
# driver = webdriver.Chrome(service=s)
#获取网址
url="http://10.115.148.102:84/#/login"
driver.get(url)
# 窗口最大化
driver.maximize_window()
driver.find_element(By.ID,'username').send_keys('21024.admin')
driver.find_element(By.ID,'password').send_keys('qwer.1234')
driver.find_element(By.NAME,'登录页面-登录栏-登录按钮').click()
通过name定位元素
driver.find_element(By.NAME,**'登录页面-登录栏-登录按钮'**)
通过class定位元素
driver.find_element(By.CLASS_NAME,**'登录页面-登录栏-登录按钮'**)