selenium 9222

直接连接9222 会等待很长时间,多线程尝试连接9222,join(timeout=2),结果放brower。

如果brower是空,os执行 chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\selenum\AutomationProfile" ,然后在主线程再次连接9222

python 复制代码
import os

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from threading import Thread

# 直接连接9222 会等待很长时间
# 多线程尝试连接9222,join(timeout=2)
# if brower ='',
# os执行 chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\selenum\AutomationProfile"
# 再次连接9222

brower = ''
chrome_options = Options()
chrome_options.add_experimental_option('debuggerAddress', "127.0.0.1:9222")


def connect():
    global brower
    brower = webdriver.Chrome(executable_path="???",
                              chrome_options=chrome_options)


t = Thread(target=connect)
t.start()
t.join(2)
if brower == '':
    os.system('chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\selenum\AutomationProfile"')
    connect()
    
# 浏览器操作
    
相关推荐
云和数据.ChenGuang38 分钟前
pycharm怎么将背景换成白色
ide·python·pycharm
我的xiaodoujiao1 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 25--数据驱动--参数化处理 Excel 文件 2
前端·python·学习·测试工具·ui·pytest
DO_Community1 小时前
基于AI Agent模板:快速生成 SQL 测试数据
人工智能·python·sql·ai·llm·ai编程
汪汪队立大功1232 小时前
selenium中执行javascript,是否等价于在浏览器console位置执行
javascript·selenium·测试工具
kewu89712 小时前
Postman 完全入门教程
测试工具·lua·postman
Q_Q5110082853 小时前
python+django/flask的宠物用品系统vue
spring boot·python·django·flask·node.js·php
hmbbcsm3 小时前
练习python题目小记(五)
开发语言·python
蓝桉~MLGT3 小时前
Python学习历程——文件
python·学习·策略模式
循环过三天3 小时前
7.5、Python-匿名函数lambda
笔记·python·学习