从带有标志的命令行运行chrome --use-mobile-user-agent不会在移动上下文(用户代理)中打开浏览器.
chrome --use-mobile-user-agent= true
注意:
传递用户代理选项确实有效,但我觉得它不是正确的做事方式,因为chrome为你提供了这个标志,可以在移动环境中启动.
--user-agent= Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; ar) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3
阅读一些铬源代码,我看到以下内容:
kUseMobileUserAgent从"use-mobile-user-agent"标志定义:当Chromium使用移动用户代理时设置.
const char kUseMobileUserAgent[] = "use-mobile-user-agent";
如果我们的变量开关为真/设置,则将"Mobile"添加到产品.
std::string GetShellUserAgent() {
  std::string product = "Chrome/" CONTENT_SHELL_VERSION;
  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
  if (command_line->HasSwitch(switches::kUseMobileUserAgent))
    product += " Mobile";
  return BuildUserAgentFromProduct(product);
}
作为额外的细节,我使用selenium运行chrome并传递配置:
 ...
 "browserName": "chrome",
 "chromeOptions": {
     "args": [ …如果任何表单输入更改,如何立即更改提交按钮文本?
//This applies to whole form
$('#test').change(function() {
  $("#send").prop("value","Change");
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form id="test">
  <input id="Input1" value="Input1" />
  <input id="Input2" value="Input2" />
  <input type="submit" id="send" value="Send" />
</form>这里,光标离开输入后按钮文本发生变化.