python自动打开edge浏览器

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中存储的动作
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要通过Python调用Edge浏览器,你可以使用Selenium库。以下是使用Selenium和Edge浏览器的基本步骤: 1. 安装所需库:首先,确保你的Python环境中安装了Selenium库。你可以使用pip命令进行安装: ``` pip install selenium ``` 2. 下载Microsoft WebDriver:Edge浏览器需要使用Microsoft WebDriver来进行自动化控制。你需要根据你的Edge浏览器版本下载相应的Microsoft WebDriver,并将其解压到一个路径下。 3. 导入所需库:在Python脚本中,导入需要的库: ```python from selenium import webdriver ``` 4. 配置Edge浏览器和WebDriver:使用`webdriver.Edge`类来创建一个Edge浏览器的WebDriver实例,并指定WebDriver的路径: ```python driver_path = 'path/to/edgedriver.exe' # 替换为你的WebDriver路径 driver = webdriver.Edge(executable_path=driver_path) ``` 5. 使用WebDriver控制Edge浏览器:通过WebDriver对象,你可以控制Edge浏览器的行为,例如打开网页、点击元素等。以下是一个打开网页的示例: ```python driver.get('https://www.example.com') # 替换为你要访问的网页URL ``` 6. 进行其他操作:根据你的需求,你可以使用WebDriver对象执行其他操作,如查找元素、填写表单、点击按钮等。 7. 关闭浏览器:在使用完Edge浏览器之后,记得关闭WebDriver对象,以释放资源: ```python driver.quit() ``` 以上就是使用Python调用Edge浏览器的基本步骤。请注意,使用Selenium进行浏览器自动化需要合法、合规的使用,遵守相关的法律和规定。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值