selenium操作已开启的浏览器,方便调试

一、谷歌浏览器配置:

在所安装的谷歌下面,执行下面命令,打开谷歌浏览器,用来selenium的操作:

注意事项:端口需要不被占用,--user-data-dir="D:\workspace\chrome-data"这个路径需要有权限访问,不能放在一个需要管理员访问的路径下,否则浏览器打不开

复制代码
chrome.exe --remote-debugging-port=9222 --user-data-dir="D:\workspace\chrome-data"

二、selenium配置:

下面是新版selenium的配置:

复制代码
import logging
from selenium import webdriver
from page_object.searchpage import SearchPage

logging.basicConfig(level=logging.DEBUG)

options = webdriver.ChromeOptions()
options.add_experimental_option("debuggerAddress", "localhost:9222")

driver = webdriver.Chrome(options=options)

# 访问网址
driver.get("http://www.baidu.com")
print(driver.title)
search = SearchPage(driver)
search.input_search("selenium")

老版selenium配置为:

复制代码
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
driver = webdriver.Chrome(chrome_options=chrome_options)

运行效果:

执行代码时有时会比较慢,需要有点耐心。

相关推荐
把头塞进显示器2 天前
电商平台-测试报告
python·selenium·pytest
霍格沃兹测试学院-小舟畅学3 天前
UI 测试的语义断言:Midscene aiAssert 比像素比对稳在哪、又会骗在哪
人工智能·测试工具
zuozewei3 天前
附录 A:主流工具对比选型表
人工智能·测试工具
我的xiaodoujiao3 天前
Django 基础知识详细图文教程 10-Django 模板引擎 3
后端·python·测试工具·django
霍格沃兹测试学院-小舟畅学3 天前
Google 开源 ARTEMIS:AI Agent 如何接管 Android 真机测试?
人工智能·测试工具
Liaiyang663 天前
# 自研 AST 容错初筛工具:横向评测 Django、PyTorch、TensorFlow 三大开源 Python 框架异常收容风险
python·测试工具·自动化·开源软件·代码规范·devops·代码复审
霍格沃兹测试学院-小舟畅学3 天前
我用 AI 把 Swagger 变成 500 条 pytest 用例,回归从 3 天到 3 小时
人工智能·测试工具
奔跑中的小象4 天前
GuideLLM 压测实战指南:给大模型推理服务做一次完整 SLA 评估
测试工具·guidellm
cpolar技术支持4 天前
本地 Playwright 测试报告怎么远程复盘?Trace Viewer 跑起来后,用 cpolar 分享失败现场
前端·自动化测试·测试工具·cpolar·playwright
测试狗科研平台5 天前
材料热传导能力表征——热导率计算方法与流程解析
科技·测试工具·材料工程