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 分钟前
一文了解UI自动化测试
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
tryCbest3 小时前
Selenium中XPath定位元素详细教程
selenium·测试工具
tryCbest3 小时前
Selenium中设置Edge浏览器
selenium·测试工具·edge
Derrick__15 小时前
Selenium的使用
selenium·测试工具
想要打 Acm 的小周同学呀16 小时前
爬虫相关的面试问题
爬虫·selenium·职场和发展
IT19951 天前
Wireshark笔记-DNS流程与数据包解析
笔记·测试工具·wireshark
Hacker_Fuchen1 天前
外包干了一个月,技术明显进步。。。。。
自动化测试·软件测试·测试工具·职场和发展
测试19982 天前
Appium使用指南与自动化测试案例详解
自动化测试·软件测试·python·测试工具·职场和发展·appium·测试用例
程序员三藏3 天前
快速弄懂POM设计模式
自动化测试·软件测试·python·selenium·测试工具·设计模式·职场和发展
程序员三藏3 天前
使用Docker和Selenium构建自动化测试环境
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例