Reputation: 135
In order to set a custom user-agent of browser used by robot framework, I've found every where that you can set that like that :
${options}= Evaluate
... sys.modules['selenium.webdriver'].ChromeOptions()
... sys, selenium.webdriver
Call Method ${options}
... add_argument --user-agent\=User agent with spaces
Create WebDriver Chrome chrome_options=${options}
Go To https://www.whatismybrowser.com/detect/what-is-my-user-agent
But the value of the add_argument User agent with spaces
is not escaped and it adds unwanted wrong tabs in the browser :
The user agent detected by whatismybrowser.com is User
.
My question is pretty simple, how do I pass argument values that have spaces ?
I've tried :
User agent with spaces
User\ agent\ with\ spaces
User\\ agent\\ with\\ spaces
User${SPACE}agent${SPACE}with${SPACE}spaces
User\${SPACE}agent\${SPACE}with\${SPACE}spaces
"User agent with spaces"
'User agent with spaces'
None of these works...
Upvotes: 2
Views: 1214
Reputation: 135
I've found the root cause of my problem.
While searching deeper about my problem, I've found that question that is exactly the problem I had too : add_argument for user agent cuts off at first space
I'm using a robot-framework docker image here : https://github.com/ppodgorsek/docker-robot-framework
The binary launcher bin/chromium-browser.sh
contains the bash positional argument operator unquoted :
#!/bin/sh
exec /usr/lib/chromium/chrome-original --disable-gpu --no-sandbox $@
Replacing that with a quoted positional argument operator solve the problem and I can set a custom user-agent of the controlled browser.
#!/bin/sh
exec /usr/lib/chromium/chrome-original --disable-gpu --no-sandbox "$@"
Upvotes: 3