I would like to use a data structure to send the options to the Selenium Open-browser interface.

The documentation of the library tells that it accepts type 'Any', therefore a list or dictionary or any combination is assumed to be allowed.

Sending the options as a long string does work.

add_argument("--no-sandbox"); add_argument("--disable-web-security"); add_argument("--disable-software-rasterizer"); add_argument("--proxy-server=http://10.10.10.10:80") 

but not sending it as a data structure such as:

[{'add_argument': ['--no-sandbox']}, {'add_argument': ['--disable-web-security']}, {'add_argument': ['--disable-software-rasterizer']}, {'add_argument': ['--proxy-server=http://10.10.10.10:80']}]

The error message here is:

AttributeError: 'list' object has no attribute 'capabilities' 

I have tried many other data structures but none has worked.

The setup is:

RobotFramework 7.0

RobotFramework-SeleniumLibrary 6.2.0

Selenium 4.18.1

Python 3.12

${arguments}     Create List
${options}       Create List
Append To List  ${options}  --no-sandbox
Append To List  ${options}  --disable-web-security
Append To List  ${options}  --disable-software-rasterizer
Append To List  ${options}  --proxy-server=http://10.10.10.10:80
FOR  ${elem}  IN   @{options}
  ${elem_list}   Create list  ${elem}
  ${dict}  Create Dictionary  add_argument  ${elem_list}
  Append To List  ${arguments}  ${dict}
END
Log To Console    ${arguments}
${current_open_window}=  Open Browser  browser=Chrome  options=add_argument("--no-sandbox"); add_argument("--disable-web-security"); add_argument("--disable-software-rasterizer"); add_argument("--proxy-server=http://10.10.10.10:80")
1

There are 1 best solutions below

0
Edwin On

Solved by using an object.

from selenium import webdriver

class seleniumOptions:
  def get_options(self):
    options = webdriver.ChromeOptions()
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-web-security')
    options.add_argument('--disable-software-rasterizer')
    options.add_argument('--proxy-server=10.10.10.10:80')
    return options