我正在尝试自动化与生成MIME类型为application / vnd.wap.xhtml xml的文档的网站的交互 . 我正在使用Selenium 2,WebDriver和FirefoxProfile .
由于Firefox不处理上述MIME类型,因此我需要使用XHTML Mobile Profile扩展(https://addons.mozilla.org/en-US/firefox/addon/1345/)运行Firefox .
创建FireFox配置文件后 - 我将其命名为“selenium”并安装Mobile Profile扩展程序,我尝试使用“Selenium 2.0和WebDriver”文档的“提示和技巧”部分中的代码片段(http:// seleniumhq) .ORG /文档/ 09_webdriver.html#的HtmlUnit驱动器) .
方法#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/");
无论我使用什么代码片段,启动的浏览器实例始终无法处理生成的内容;浏览器提示我采取措施来处理无法识别的MIME类型的内容,就好像扩展名未正确配置一样 .
关于我可能做错的任何想法?
提前致谢,
3 回答
尝试从空白配置文件开始并在运行时添加扩展/配置:
希望这会帮助你:
您必须确保将浏览器插件添加为testsettings文件中的DeploymentItem . 一些例子(在这一个我们添加了Firebug):
然后,您需要创建一个如下所示的配置文件:
如果您使用AddExtension添加扩展,则它应该在您的selenium驱动程序中可用 . 我希望这有帮助 .