Selenium 2 WebDriver 使用自定义配置文件
我正在尝试自动与生成 MIME 类型 application/vnd.wap.xhtml+xml 文档的网站进行交互。我正在使用 Selenium 2、WebDriver 和 FirefoxProfile。
由于 Firefox 不处理上述 MIME 类型,因此我需要使用 XHTML Mobile Profile 扩展运行 Firefox (https://addons.mozilla.org/en-US/firefox/addon/1345/)。
创建 FireFox 配置文件(我将其命名为“selenium”)并安装移动配置文件扩展后,我尝试使用“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 类型的内容采取操作,就好像扩展程序未正确配置一样。
关于我可能做错了什么有什么想法吗?
提前致谢,
I'm trying to automate the interaction with a website that generates documents with MIME type application/vnd.wap.xhtml+xml. I am using Selenium 2, the WebDriver and the FirefoxProfile.
Because Firefox does not handle the above mentioned MIME type, I need to run Firefox with the XHTML Mobile Profile extension (https://addons.mozilla.org/en-US/firefox/addon/1345/).
After creating a FireFox profile -I named it 'selenium'- and installing the Mobile Profile extension, I tried to use the code snippets in the 'Tips and Tricks' section of the 'Selenium 2.0 and WebDriver' document (http://seleniumhq.org/docs/09_webdriver.html#htmlunit-driver).
Approach #1 looks like this:
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"));
Approach #2 looks like this:
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/");
No matter what code snippet I use, the browser instance that starts up is always unable to handle the generated content; the browser prompts me for an action to take on the content of the unrecognized MIME type as if the extension was not correctly configured.
Any ideas on what I could be doing wrong?
Thanks in advance,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试从空白配置文件开始并在运行时添加扩展/配置:
Try starting with a blank profile and adding extensions/configurations at runtime:
希望这会对您有所帮助:
Hope this will help you out:
您必须确保将浏览器插件添加为 testsettings 文件中的 DeploymentItem。
一些示例(在本例中我们添加了 Firebug):
然后,您需要创建一个如下所示的配置文件:
如果您使用 AddExtension 添加扩展,则它应该在您的 selenium 驱动程序中可用。我希望这有帮助。
You have to make sure you add the browser plugin as a DeploymentItem in your testsettings file.
Some examples (in this one we have added Firebug):
You will then need to create a profile that looks something like this:
If you add the extension using AddExtension, it should be available within you selenium driver. I hope this helps.