chrom本地调试 selenium调试本地浏览器

chrom本地调试  selenium调试本地浏览器

1、cmd命令窗口执行下面命令,生成指定端口的chrom窗口。

 终端执行chrome.exe完整路径 --remote-debugging-port=9222 --user-data-dir="自定义用户信息文件夹路径",端口可修改。

D:\Desktop\item\chromtest\Chrome\Application>chrome.exe --remote-debugging-port=9222 --user-data-dir="D:\Desktop\item\chromtest\Chrome\Application\test"

 

2.python脚本执行

复制代码
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from time import sleep
from selenium.webdriver.chrome.options import Options


chrome_options = Options()
# chrome_options.add_argument('--headless')
# chrome_options.add_argument('--disable-gpu')
# chrome_options.add_argument('--no-sandbox')
# chrome_options.add_argument('--ignore-certificate-errors')
# chrome_options.add_argument('--no-sandbox')
# chrome_options.add_argument('--disable-dev-shm-usage')
# chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])

# chrome_options.add_experimental_option('detach', True)


def check_handles():
    handles = bro.window_handles
    bro.switch_to.window(handles[-1])
def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('PyCharm')
    chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")

    bro = webdriver.Chrome(service=Service('./chromedriver.exe'),options=chrome_options)
    bro.get('https://baidu.com')  #此处换成自己的地址
    bro.maximize_window()
    sleep(2)
    check_handles()
    bro.find_element(By.XPATH, '//*[@id="app"]/div/div[2]/div/div[3]/div[2]/div[4]/div[2]/div[2]/div').click()  # 去答题
复制代码
posted @   小小仓鼠  阅读(192)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示