【发布时间】:2011-06-03 17:46:39
【问题描述】:
我正在尝试自动与生成具有 MIME 类型 application/vnd.wap.xhtml+xml 的文档的网站进行交互。我正在使用 Selenium 2、WebDriver 和 FirefoxProfile。
由于 Firefox 不处理上述 MIME 类型,我需要使用 XHTML 移动配置文件扩展 (https://addons.mozilla.org/en-US/firefox/addon/1345/) 运行 Firefox。
创建 FireFox 配置文件(我将其命名为“selenium”)并安装 Mobile Profile 扩展后,我尝试使用“Selenium 2.0 和 WebDriver”文档的“提示和技巧”部分中的代码 sn-ps( http://seleniumhq.org/docs/09_webdriver.html#htmlunit-driver)。
方法 #1 如下所示:
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile profile = allProfiles.getProfile("selenium");
profile.setPreference("general.useragent.override", "User Agent string to force application/vnd.wap.xhtml+xml content..");
FirefoxDriver driver = new FirefoxDriver(profile);
driver.get("http://www.mobilesite.com/");
WebElement element = driver.findElement(By.tagName("body"));
方法 #2 如下所示:
File profileDir = new File("/path/to/custom/profile/with/extension/ffprofile");
FirefoxProfile profile = new FirefoxProfile(profileDir);
profile.setPreference("general.useragent.override", "same user agent string as above");
FirefoxDriver driver = new FirefoxDriver(profile);
driver.get("http://www.mobilesite.com/");
无论我使用什么代码sn -p,启动的浏览器实例总是无法处理生成的内容;浏览器提示我对无法识别的 MIME 类型的内容执行操作,就像未正确配置扩展一样。
关于我可能做错的任何想法?
提前致谢,
【问题讨论】:
-
也许你最好问问 selenium 支持论坛?
-
我一定会的。谢谢你的建议。 StackOverflow 社区令人印象深刻,它已成为我解决所有问题的第一站... :)
-
当 Selenium 启动插件时,您是否能够验证插件是否正在被 Firefox 加载? (例如,确保测试没有关闭它启动的浏览器,然后查看加载项是否显示在加载项窗口中。如果没有,那么我可能会尝试几件事:命名您的配置除 Selenium 以外的其他东西(如果 Selenium 称之为它自己创建的默认配置文件),或者尝试使用 Ruby 绑定为 Firefox 配置文件提供的 add_extension 方法的 Java 等效项,以自动将扩展加载到 Selenium 的配置文件中。
-
请在 selenium 支持论坛中添加问题的直接链接...如果您添加了它。这个问题与我高度相关,答案也是如此:)
-
完成! :) 不幸的是,没有人在这里或 Selenium 用户组中提供答案。祝你好运!
标签: java testing selenium firefox3.6