在 Selenium RC 中设置用户代理

发布于 2024-10-09 11:13:18 字数 1174 浏览 0 评论 0原文

在 Selenium RC 中使用自定义标头的主要思想是将用户代理和电话号码添加到我的 HTTP 请求中。为此,我使用 Selenium Server 作为 Firefox 中的代理(请参阅 如何使用 addCustomRequestHeader正确

这或多或少是我正在使用的代码:

@Before
public void setUp() throws Exception {

    setUp(URL, NAVIGATOR);

    selenium.start("addCustomRequestHeader=true");
    Thread.sleep(5000);
    selenium.windowMaximize();
}

@Test
public void testVerifyHomePage() {

    System.out.println("**** testVerifyHomePage Executing");

    selenium.addCustomRequestHeader("x-Nokia-Msisdn", "525554003650");
    selenium.addCustomRequestHeader("User-Agent","Mozilla/5.0 (iPhone;");

    selenium.open(URL);
    selenium.waitForPageToLoad("30000");

    verifyTextPresentErrorMsg(selenium,"Home Page");

    System.out.println("---- testVerifyHomePage Finished");

}

x-Nokia-Msisdn 发送正确,但用户代理错误(它始终认为我的用户代理是 Moxilla Firefox 而不是移动设备)电话)。我尝试访问 YouTube 等页面,但未显示移动版本,因此这意味着我发送的用户代理未被考虑在内。

我在互联网上搜索,发现有人有同样的问题,但没有可行的解决方案。有些人建议在 Firefox + 修改标题中使用特定的配置文件,但我认为这是不可能的,因为每次 Selenium 启动 Firefox 实例时,它都会创建一个没有插件的普通版本。

有什么建议吗?

The main idea of using the Custom Headers in Selenium RC was to add the User-agent and the phone nomber to my HTTP requests. For that purpose, I'm using Selenium Server as a proxy in Firefox (see how-to use addCustomRequestHeader properly)

This is more or less the code I'm using:

@Before
public void setUp() throws Exception {

    setUp(URL, NAVIGATOR);

    selenium.start("addCustomRequestHeader=true");
    Thread.sleep(5000);
    selenium.windowMaximize();
}

@Test
public void testVerifyHomePage() {

    System.out.println("**** testVerifyHomePage Executing");

    selenium.addCustomRequestHeader("x-Nokia-Msisdn", "525554003650");
    selenium.addCustomRequestHeader("User-Agent","Mozilla/5.0 (iPhone;");

    selenium.open(URL);
    selenium.waitForPageToLoad("30000");

    verifyTextPresentErrorMsg(selenium,"Home Page");

    System.out.println("---- testVerifyHomePage Finished");

}

The x-Nokia-Msisdn is sent correctly but the User-Agent is wrong (it always considers that my User-Agent is Moxilla Firefox and not a mobile phone). I've tried accessing to pages such as YouTube and the mobile version isn't displayed so this means that the User-Agent that I'm sending is not taken into account.

I've search on the internet and I found people with the same issue but no possible solution. What some people suggest is using a particular profile in Firefox + Modify Headers but I don't think this is possible since everytime Selenium starts an instance of Firefox it creates a plain version without addons.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感悟人生的甜 2024-10-16 11:13:18

Selenium RC:设置 Firefox 代理

这是为了记录在 Firefox 中使用 Selenium RC 设置代理参数,但它描述了如何使用 Firefox 配置文件管理器。

使用它,您可以使用您想要的任何设置和附加组件来调用 Firefox

Selenium RC : Setting up a Firefox proxy

This was to document setting up proxy arguments inside Firefox with Selenium RC but it describes how to use the Firefox Profile Manager.

Using this, you can invoke Firefox with whatever settings and add-ons you want

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文