1

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.

Vinaykumar Patel
  • 864
  • 11
  • 26

2 Answers2

3

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.

A. Kootstra
  • 6,827
  • 3
  • 20
  • 43
0

I used the similar structure as defined in the solution but still another browser is getting opened for me instead of the already opened browser

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34452105) – user16217248 Jun 01 '23 at 17:38