0

I've seen the example in Create Webdriver for Firefox proxy. However I don't have any idea on how to implement this on Chrome.

Edited this question to display the version of installed packages in my machine:

  • ChromeDriver 2.25.426935
  • Google Chrome Version 56.0.2924.87 (64-bit)
  • robotframework (3.0)
  • robotframework-selenium2library (1.8.0)
  • selenium (3.0.2)
rekyn
  • 3
  • 2
  • 3

2 Answers2

3

ChromeDriver supports using a predefined proxy as well, but you have to specify it as a command line argument in the ChromeOptions object which you can pass when creating a ChromeDriver. See this answer for how to do it in python for example: https://stackoverflow.com/a/11821751/7433999

When using then Selenium2Library and the Create Webdriver keyword it should be possible to achieve the same, if you construct a chrome_options dictionary in the correct form, and pass it to the keyword.

Something like this could work:

${args}=                | Create List       | --proxy-server=1.2.3.4:8080
${chrome_options}=      | Create Dictionary | args=${args}
Create WebDriver        | Chrome            | chrome_options=${chrome_options}
Community
  • 1
  • 1
ralph.mayr
  • 1,320
  • 8
  • 12
  • I encountered an error: `AttributeError: to_capabilities` while running the exact same code above (just altered the proxy server value). – rekyn Jan 30 '17 at 01:19
  • Thank you very much, @ralph.mayr , for actively helping me out. As for your question, there is no specific line in which the error occurs. Here is the [screenshot](https://i.stack.imgur.com/bDLa2.png) of the `log.html`. – rekyn Feb 02 '17 at 09:02
  • The `to_capabilities` error is because an `Options` object will have this method. As mayr said in the first paragraph, `chrome_options` expect a `selenium.webdriver.chrome.options.Options` object. However in the code snippet the variable `${chrome_options}` is a `dict` object with value `"args": "--proxy-server=1.2.3.4:8080"` instead of a proper `Options` object. – kaltu Dec 28 '20 at 04:31
1

To use ChromeOptions in RobotFramework you may want to do something like:

In ./project_root/my_library.py

from typing import Union
from selenium.webdriver.chrome.options import Options
def Get_Proxy_Option(url: str, port: Union[int, str]) -> Options:
    options = Options()
    options.add_argument(f"--proxy-server={url}:{port}")
    return options

In ./project_root/my_testcase.robot

*** Settings ***
Library    SeleniumLibrary
Library    ./my_library.py


*** Keywords ***
Open Browser With Proxy
    [Arguments]    ${browser_url}    ${proxy_url}=url.to.proxy    ${proxy_port}=8080
    ${options}=    Get_Proxy_Options    @{ext_paths}    url=${proxy_url}    port=${proxy_port}
    Open Browser    ${url}    Chrome    options=${options}

ref: https://selenium-python.readthedocs.io/api.html#selenium.webdriver.chrome.options.Options.add_argument

kaltu
  • 330
  • 5
  • 17