【问题标题】:Robot Framework calling add_argument with spaces机器人框架调用带有空格的 add_argument
【发布时间】:2021-05-05 19:31:20
【问题描述】:

为了设置机器人框架使用的浏览器的自定义用户代理,我找到了你可以这样设置的每个地方:

    ${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

但是 add_argument User agent with spaces 的值没有被转义,它在浏览器中添加了不需要的错误标签:

whatismybrowser.com 检测到的用户代理是User

我的问题很简单,如何传递有空格的参数值?

我试过了:

  • 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'

这些都不起作用...

【问题讨论】:

  • 你可以试试三引号'''用户代理带空格'''

标签: selenium-webdriver robotframework user-agent


【解决方案1】:

我找到了问题的根本原因。

在深入研究我的问题时,我发现这个问题正是我遇到的问题:add_argument for user agent cuts off at first space

我在这里使用机器人框架 docker 映像:https://github.com/ppodgorsek/docker-robot-framework

二进制启动器bin/chromium-browser.sh 包含不带引号的bash 位置参数运算符:

#!/bin/sh

exec /usr/lib/chromium/chrome-original --disable-gpu --no-sandbox $@

用带引号的位置参数运算符替换它可以解决问题,我可以设置受控浏览器的自定义用户代理。

#!/bin/sh

exec /usr/lib/chromium/chrome-original --disable-gpu --no-sandbox "$@"

【讨论】:

    猜你喜欢
    • 2016-02-02
    • 1970-01-01
    • 2020-07-10
    • 2015-09-28
    • 1970-01-01
    • 2017-11-02
    • 2019-02-18
    • 2018-05-01
    • 2018-11-23
    相关资源
    最近更新 更多