from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.service import Service
service = Service(executable_path=r'C:\Program Files (x86)\Microsoft\Edge\Application\msedgedriver.exe')
# 设置浏览器参数,让浏览器不自动关闭
option = webdriver.EdgeOptions()
option.add_experimental_option("detach", True)
# 设置浏览地址
driver = webdriver.Edge(service=service, options=option)
# 设置打开的网址
driver.get('http://127.0.0.1:8082/platform/login')
# 设置浏览器全屏显示
driver.maximize_window()
# 设置自动刷新
driver.refresh()
# 该元素的所有class都需要填写上
text_label = driver.find_element(By.XPATH, '//*[@class="form-control uname"]')
text_label.send_keys('admin')
text_label1 = driver.find_element(By.XPATH, '//*[@class="form-control pword"]')
text_label1.send_keys('admin123')
# 定位搜索按钮
button = driver.find_element(By.XPATH, '//*[@class="btn btn-success btn-block"]')
# 执行单击操作
button.click()
1.python 中获取元素最简单的方法:
本电脑模板:
button = driver.find_element(By.XPATH, '//*[@class="btn btn-success btn-block"]')
2.鼠标事件:
click() | 单击左键 |
context_click() | 单击右键 |
double_click() | 双击 |
drag_and_drop() | 拖动 |
move_to_element() | 鼠标悬停 |
perform() | 执行所有ActionChains中存储的动作 |