selenium-webdriver - 使用 RobotFramework 将现有的 Chrome 浏览器与远程调试端口一起使用
问题描述
我正在尝试使用 RobotFramework (SeleniumLibrary) 使用现有的 google chrome 实例。我正在像这样启动 chrome 实例
chrome.exe --remote-debugging-port=9289 --user-data-dir="D:\gcdata"
这是我在机器人框架中的代码
${options}= Evaluat sys.modules['selenium.webdriver'].ChromeOptions() sys,selenium.webdriver
${prefs}= Create Dictionary debuggerAddress 127.0.0.1:9289
Call Method ${options} add_experimental_option prefs ${prefs}
Create WebDriver Chrome chrome_options=${options}
当我运行 RobotFramework 代码时,它会调用一个新的浏览器。任何人都可以在这里帮助我告诉我出了什么问题以及如何解决它。
解决方案
使用最新版本的 Python Selenium 模块、Chrome 和 ChromeDriver,以下机器人脚本将连接到已运行的 chrome,该 chrome 使用以下命令启动:
chrome.exe --remote-debugging-port=9289 --user-data-dir="C:\temp\gdata"
chrome_debugger.robot
*** Settings ***
Library SeleniumLibrary
Library Collections
*** Test Cases ***
TC
${ChromeOptions}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys,selenium.webdriver
# Method debugger_address is not callable so convert to Capabilities Dictionary and set it manually
${ChromeCapabilities}= Call Method ${ChromeOptions} to_capabilities
Set To Dictionary ${ChromeCapabilities["goog:chromeOptions"]} debuggerAddress 127.0.0.1:9289
# Instead of using the Chrome Options use Capabilities.
Create WebDriver Chrome desired_capabilities=${ChromeCapabilities}
Go To http://cnn.com
即使ChromeOptions
类 ( GitHub ) 具有该debugger_address(self, value)
方法,从 Robot Framework 调用此方法也会返回错误。因此,将ChromeOptions
类转换为Capabilities
字典并手动将其添加到字典中,然后再通过参数将其传递给 webdriver desired_capabilities
。
推荐阅读
- html - 在另一个 div 中显示 3 个 div 的方法在移动视图中无法正确显示
- php - 如何获取 Symfony 中所有实体的列名?
- python - 使用python切换win 10上的“夜灯”功能
- flutter - 当我按下下载按钮时如何显示带有 CircularProgressIndicator 和下载状态的弹出窗口
- node.js - 如何在 Node.js 中获取和传递变量
- perl - GD::Graph::pie 的值的铭文
- angular - 检查字符串中是否包含一组字符串
- javascript - 未捕获的 ReferenceError:setValue 未在 HTMLDivElement.onclick 中定义
- module - Coq - 统一来自具有相同参数的模块仿函数的类型?
- autodesk-forge - 优化 Forge Design Automation 调用