【问题标题】:Use Selenium to attach to a manually opened Browser使用 Selenium 附加到手动打开的浏览器
【发布时间】:2021-08-06 04:37:31
【问题描述】:

我知道,以前在这里已经提出过这样的问题,但它已有 4 年历史,并没有多大帮助。 所以,我想做的很简单,我想要我的 selenium(在 C# 中的 WPF 和 .Net 5.0 中运行)所以连接到一个打开的浏览器来控制它。使用调试端口 9222 手动打开浏览器,我可以从另一个浏览器实例成功连接到此浏览器。

我可以使用 selenium 打开新的 Chrome 浏览器并对其进行控制,但我还需要能够连接到打开的实例。

帮助会很棒。

PS:我知道 selenium 用于测试,通常不用于不受控制的测试环境。 =)

非常感谢你们的帮助。

【问题讨论】:

    标签: c# wpf selenium browser driver


    【解决方案1】:

    在浏览器中输入:chrome://version/你会得到chrome.exe的可执行路径

    复制这个并关闭所有 chrome 实例。

    **关闭所有chrome实例并**

    启动 chrome 为:

    "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --remote-debugging-port=5555
    

    通过访问 localhost:5555 验证 chrome 是否在端口打开的情况下启动

    现在添加远程调试端口为:

    var options = new ChromeOptions();
    options.debuggerAddress= "127.0.0.1:5555";
    
    var driver = new ChromeDriver(options);
    

    使用 chrromeoptions 从 selenium 连接到该端口

    【讨论】:

    • 这正是我目前的做法。但这不是我在这里要求的方式。我不想像你那样从核心打开浏览器。我想连接到已经打开的浏览器
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    • 2017-08-01
    • 1970-01-01
    • 2022-01-14
    相关资源
    最近更新 更多