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)

运行效果:

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

相关推荐
废弃的小码农8 小时前
功能测试--Day02--Web项目测试
功能测试·测试工具
悟能不能悟9 小时前
怎么使用postman批量的给api做测试
测试工具·lua·postman
猿小路1 天前
抓包工具-Wireshark
网络·测试工具·wireshark
智航GIS1 天前
10.4 Selenium:Web 自动化测试框架
前端·python·selenium·测试工具
廖圣平1 天前
从零开始,福袋直播间脚本研究【三】《多进程执行selenium》
python·selenium·测试工具
合兴软件@2 天前
芯片适配快讯:合兴软件ISDT成功适配英飞凌TC3/TC4系列MCU
测试工具·车载系统·嵌入式实时数据库
Wpa.wk2 天前
性能测试-初识性能测试基础(性能测试流程,计划等)
java·运维·经验分享·测试工具·性能测试
我想吃烤肉肉2 天前
Playwright中page.locator和Selenium中find_element区别
爬虫·python·测试工具·自动化
0思必得02 天前
[Web自动化] Selenium基础介绍
前端·python·selenium·自动化·web自动化