Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open Browser 'Options' object has no attribute '' #1877

Closed
manosnoam opened this issue Jan 8, 2024 · 2 comments · Fixed by #1879
Closed

Open Browser 'Options' object has no attribute '' #1877

manosnoam opened this issue Jan 8, 2024 · 2 comments · Fixed by #1879
Milestone

Comments

@manosnoam
Copy link

When calling open browser with options that ends with ; such as:

add_argument("--ignore-certificate-errors");add_argument("window-size=1920,1024");add_argument('--no-sandbox');add_argument('--disable-gpu');add_argument('--disable-dev-shm-usage');

Then the browser will fail to open with error:

robot.errors.HandlerExecutionFailed: AttributeError: 'Options' object has no attribute ''

Once I removed the last ; then the browser was launched with the required options.

Found in RF version 6.0

@emanlove
Copy link
Member

This is due to how we parse the options string. I think that having a trailing semicolon should not throw an error. To me I could see one constructing this string somewhere and for each options adding a trailing semicolon. Thus it would be too much to ask that the last in the set does not contain a trailing semicolin.

I think it is easy enough to ignore those although I see our parsing thinks that introduces another option. I was considering similar cases like,

*** Test Cases ***
Chrome Browser with Selenium Options Ending With A Few Semicolons
    Open Browser    ${FRONT PAGE}    ${BROWSER}    remote_url=${REMOTE_URL}
    ...    desired_capabilities=${DESIRED_CAPABILITIES}    options=add_argument("--disable-dev-shm-usage") ; ; ;

Chrome Browser with Selenium Options Containing Empty Option
    Open Browser    ${FRONT PAGE}    ${BROWSER}    remote_url=${REMOTE_URL}
    ...    desired_capabilities=${DESIRED_CAPABILITIES}    options=add_argument ( "--disable-dev-shm-usage" ) ; ; add_argument ( "--headless=new" )

In these I see the option as being empty for which a warning could be helpful. But we shouldn't warn that you have an empty option for just a trailing semicolon.

@emanlove
Copy link
Member

emanlove commented Jan 14, 2024

Somewhat related, a recent question was asked on setting some download options for which the poster had this, the first test case, solution to their problem,

*** Settings ***
Library  SeleniumLibrary

*** Test Cases ***
Example Of Complex Selenium Options Using Create Dictionary
    ${Prefs}=  Create Dictionary  profile.default_content_settings.popups=0, download.default_directory=r"C:\\Users\\me\\test_downloads",download.prompt_for_download:False
    Open Browser    about:blank    Chrome    alias=UserCreate
    ...    options=add_argument("--disable-popup-blocking"); add_argument("--ignore-certificate-errors"); add_argument("--disable-gpu"); add_argument("--disable-dev-shm-usage"); add_argument("--no-sandbox");add_argument("--disable-proxy-certificate-handler");add_experimental_option("prefs", ${Prefs})

Example Of Complex Selenium Options Using Options String
   Open Browser    about:blank    Chrome    alias=UserCreate
   ...    options=add_argument("--disable-popup-blocking"); add_argument("--ignore-certificate-errors"); add_argument("--disable-gpu"); add_argument("--disable-dev-shm-usage"); add_argument("--no-sandbox");add_argument("--disable-proxy-certificate-handler");add_experimental_option("prefs", { 'profile.default_content_settings.popups' : 0 , 'download.default_directory' : r"C:\\Users\\me\\test_downloads" , 'download.prompt_for_download' : False } ) 

I was thinking one should be able to put this configuration in as a simple options string. But I see with this attempt the tokenizer fails. It is the tokenizer which parses out the trailing semicolon thinking it is expecting another option as well. Might be able to solve both these at once (although I will focus on the primary problem listed here first). Correction: My error. I had a semicolon as the dictionary key-value pair separator for some reason. As I debug this I see that the Python tokenizer is parsing Python syntax/lexicon and of course the (proper) separator is a comma. So the above code is valid and works!

One other side note is #4948 within robotfram,ework core might help with the visual problem that these options lines can get very long and would allow for multiline usage.

emanlove added a commit to emanlove/robotframework-seleniumlibrary that referenced this issue Jan 14, 2024
Within the selenium options argument of the `Open Browser` keword, if there were
trailing semicolons then the keyword would fail. With this change we allow trailing
semicolons. In addition the library warns about emtpy options.

Fixes robotframework#1877
@emanlove emanlove added enhancement priority: medium acknowledge To be acknowledged in release notes labels Jan 14, 2024
@emanlove emanlove added this to the v6.3.0 milestone Jan 14, 2024
emanlove added a commit that referenced this issue Jan 20, 2024
@emanlove emanlove added the rc 1 label Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants