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)

运行效果:

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

相关推荐
搬砖柯10 小时前
系列10-接口/UI 自动化怎么验落库?数据工厂与数据库断言实践
数据库·测试工具·ui·开源·自动化
LT101579744412 小时前
2026年在线兼容性测试工具推荐|零部署网页 / APP / 小程序实测对比
测试工具·小程序
程序员杰哥18 小时前
接口自动化测试项目框架详解
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·接口测试
灵翼飞航科技有限公司2 天前
2026款WF-EN系列多功能发动机测试台(适用DLE、林巴赫、Rotax等发动机)
功能测试·测试工具·无人机
ClouGence3 天前
Selenium、Playwright、CueCast 深度对比:Web 自动化测试工具怎么选
selenium·测试
程序员小远19 天前
自动化测试基础知识总结
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
LT101579744419 天前
2026年Web自动化测试工具选型指南:多浏览器兼容解决方案
前端·测试工具·自动化
程序员三藏19 天前
Web自动化测试详解
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
深蓝电商API19 天前
Selenium 5.0 全新架构解析:值得升级吗?
爬虫·selenium