问题
I am trying to use existing google chrome instance using RobotFramework (SeleniumLibrary). I am starting the chrome instance like this
chrome.exe --remote-debugging-port=9289 --user-data-dir="D:\gcdata"
This my code in robotframework
${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}
When I run the RobotFramework code, it invokes a new browser. Can anyone help me here telling what is going wrong and how to fix it.
回答1:
Using the most recent versions of the Python Selenium Module, Chrome and ChromeDriver the following Robot script will connect to an already running chrome that is started using:
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
Even though the ChromeOptions
class (GitHub) has the debugger_address(self, value)
method, calling this method from Robot Framework returns an error. Therefore converting the ChromeOptions
class to a Capabilities
dictionary and adding it manualy to the dictionary before passing it to the webdriver through the desired_capabilities
argument.
来源:https://stackoverflow.com/questions/53322326/use-existing-chrome-browser-with-remote-debugging-port-using-robotframework