我正在尝试自动与生成具有 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”文档(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/");
无论我使用什么代码片段,启动的浏览器实例总是无法处理生成的内容;浏览器提示我对无法识别的 MIME 类型的内容执行操作,就像未正确配置扩展一样。
关于我可能做错了什么的任何想法?
提前致谢,