【selenium】webdriver测试脚本

【背景】

不同电脑上运行selenium时总是因为环境问题出幺蛾子,所以需要一个最简单的脚本每次先验证一下能不能正常启用selenium。

【脚本】

这个脚本做的事情就是试着用selenium启动网页,默认用了百度首页,也可以根据情况自己修改。

python 复制代码
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

# 创建Chrome浏览器的选项
chrome_options = Options()
chrome_options.add_argument("--start-maximized")  # 启动时最大化窗口
chrome_options.add_argument("--disable-infobars")  # 禁用信息提示栏
chrome_options.add_argument("--disable-extensions")  # 禁用扩展

# 设置ChromeDriver的路径
chrome_driver_path = "chromedriver.exe"  # 替换为你的chromedriver路径
service = Service(chrome_driver_path)

# 启动Chrome浏览器
driver = webdriver.Chrome(service=service, options=chrome_options)

# 打开指定网页
driver.get("http://www.baidu.com")  # 替换为你想打开的网址

input()

# 关闭浏览器
driver.quit()
相关推荐
Run Freely9371 小时前
接口测试-postman-全局变量与环境变量
测试工具·postman
我的xiaodoujiao4 小时前
从 0 到 1 搭建 Python 语言 Web UI自动化测试学习系列 8--基础知识 4--常用函数 2
前端·python·测试工具·ui
程序员小远7 小时前
常用的测试用例
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
(时光煮雨)8 小时前
【Python进阶】Python爬虫-Selenium
爬虫·python·selenium
依旧很淡定2 天前
Selenium(Python)创建Chrome浏览器实例
chrome·python·selenium
小熊出擊2 天前
【pytest】finalizer 执行顺序:FILO 原则
python·测试工具·单元测试·pytest
云闲不收2 天前
接口请求工具对比 apifox apipost swagger postman等
测试工具·postman
sitellla3 天前
Testify Go测试工具包入门教程
git·测试工具·其他·golang
我的xiaodoujiao3 天前
从 0 到 1 搭建 Python 语言 Web UI自动化测试学习系列 9--基础知识 5--常用函数 3
前端·python·测试工具·ui
可可南木3 天前
ICT 数字测试原理 8 - -VCL 的测试参数
开发语言·功能测试·测试工具·pcb工艺