本文将为您提供关于如何在Selenium中使用自定义Firefox配置文件?的详细介绍,我们还将为您解释Java的相关知识,同时,我们还将为您提供关于Firefox配置文件中的selenium禁用插件
本文将为您提供关于如何在Selenium中使用自定义Firefox配置文件?的详细介绍,我们还将为您解释Java的相关知识,同时,我们还将为您提供关于Firefox配置文件中的selenium禁用插件、html – 一个Xpath表达式在selenium中不起作用,但在Firefox中有效、javascript – 如何在C#Selenium中向FirefoxDriverService添加配置文件规范?、php – Selenium2 firefox:使用默认配置文件的实用信息。
本文目录一览:- 如何在Selenium中使用自定义Firefox配置文件?(Java)(并通过HTML授权窗口)
- Firefox配置文件中的selenium禁用插件
- html – 一个Xpath表达式在selenium中不起作用,但在Firefox中有效
- javascript – 如何在C#Selenium中向FirefoxDriverService添加配置文件规范?
- php – Selenium2 firefox:使用默认配置文件
如何在Selenium中使用自定义Firefox配置文件?(Java)(并通过HTML授权窗口)
如何通过自定义Firefox配置文件将Selenium与Java结合使用?
答案1
小编典典我花了一天的时间尝试执行此操作,并决定在此处分享。网络上也有一些信息,但是其中大多数都有些复杂或者不是最新的…
这是我的配置:
Firefox version: 12Selenium version: 2.25Language: JavaPlatform: MacOS
- 开放终端
- 类型:(
/Applications/Firefox.app/Contents/MacOS/firefox-bin -p
根据需要更改路径) - 创建一个新的配置文件,根据需要将其保存在目录中。
- 使用此配置文件启动firefox,并根据需要添加所有附件和修改。
在硒中,使用:
FirefoxBinary binary = new FirefoxBinary();
File firefoxProfileFolder = new
File(“/Users/xxx/work/xxx/selenium/src/test/resources/firefoxprofile”);
FirefoxProfile profile = new FirefoxProfile(firefoxProfileFolder);
profile.setAcceptUntrustedCertificates(true);
webDriver = new FirefoxDriver(binary, profile);
再次在此处根据需要更改绝对路径。添加诸如autoAuth之类的附加组件,以将Firefox中的HTML授权窗口传递给此配置文件。
Firefox配置文件中的selenium禁用插件
有人可以告诉我如何使用Java为我的客户firefox配置文件禁用插件吗?我发现有几个网站显示要添加加载项,但是关于禁用插件一无所获。
我的Firefox配置文件:
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setAcceptUntrustedCertificates(true);
firefoxProfile.setAssumeUntrustedCertificateIssuer(false);
firefoxProfile.setPreference("browser.download.folderList",2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
firefoxProfile.setPreference("browser.download.dir",reportFolder);
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv,application/pdf,application/csv,application/vnd.ms-excel");
firefoxProfile.setPreference("browser.download.manager.showAlertOnComplete",false); firefoxProfile.setPreference("browser.download.manager.showAlertOnComplete",false);
firefoxProfile.setPreference("browser.download.manager.showWhenStartinge",false);
firefoxProfile.setPreference("browser.download.panel.shown",false);
firefoxProfile.setPreference("browser.download.useToolkitUI",true);
firefoxProfile.setPreference("pdfjs.disabled",true);
firefoxProfile.setPreference("pdfjs.firstRun",false);
driver = new FirefoxDriver(firefoxProfile);
问题是默认情况下启用了某些插件。Adobe Acrobat,Google Update,Java,Microsoft
Office,Flash,Director和Silverlight的Shockwave。
我需要禁用其中一些,因为它们弄乱了我的测试。
html – 一个Xpath表达式在selenium中不起作用,但在Firefox中有效
在chrome中有这样的td:
<td> "Hello world(notes:there is$)nbsp;" <a href="xxxx">[View Hierarchy]</a> </td>
但是当我在Firefox中检查相同的元素时,它没有$nbsp和双引号;
<td> Hello world <a href="xxxx">[View Hierarchy]</a> </td>
我使用FireFinder并使用xpath:
//td[text()='Hello world']
,它可以找到该元素.
但是当我使用selenium api 2.24时,它找不到那个元素.
by.xpath("//td[text()='Hello world']")
你有什么想法吗?
谢谢!
解决方法
//td[normalize-space(text())='Hello world']
编辑以下不同的评论:
这是一个XPath表达式,可能更适合一般情况:
//td[starts-with(normalize-space(.),'Hello world')]
意思是匹配< td>节点,如果整个< td>,较少的前导和尾随空格的连接字符串内容,以“Hello world”开头
javascript – 如何在C#Selenium中向FirefoxDriverService添加配置文件规范?
我将Selenium的Firefox符号暴露在ClearScript JavaScript环境中.在以下JavaScript代码中,从C#公开/导出的符号以CS为前缀.
// Preamble_Launchbrowser.js driverService = CSFirefoxDriverService.CreateDefaultService(); driverService.FirefoxBinaryPath = "C:\\Program Files\\Mozilla Firefox\\firefox.exe"; driverService.HideCommandPromptwindow = true; driverService.SuppressInitialDiagnosticinformation = true; var options = new CSFirefoxOptions(); driver = new CSFirefoxDriver(driverService,options,CSTimeSpan.FromSeconds(10)); driver.Url = "http://www.google.com.au/";
目前我不支持配置文件,但想以某种方式添加它们.如何在FirefoxDriverService的上下文中指定配置文件?
解决方法
At present I have no support for profiles,but would like to add them somehow. How would I specify a profile in the context of a FirefoxDriverService?
如果我错过了这一点,请原谅我.
只需使用此命令行firefox.exe -p启动FireFox即可创建新的配置文件.
然后,当您运行javascript时,在新创建的配置文件下的FireFox中运行它.
php – Selenium2 firefox:使用默认配置文件
有supposed to be属性控制这个,但我认为文档与源不同步,因为我可以告诉webdriver.firefox.bin是唯一的工作.例如.开始硒:
java -jar selenium-server-standalone-2.5.0.jar -Dwebdriver.firefox.bin=not-there
作品(即它抱怨).但这没有效果:
java -jar selenium-server-standalone-2.5.0.jar -Dwebdriver.firefox.profile=default
(“default”是profiles.ini中的名称,但我也尝试了“Profile0”,它是profiles.ini中的部分的名称).
我使用PHPWebdriver(使用JsonWireProtocol)访问:
$webdriver = new WebDriver("localhost","4444"); $webdriver->connect("firefox");
我试过从PHP方面做:
$webdriver->connect("firefox","",array('profile'=>'default') );
要么:
$webdriver->connect("firefox",array('profile'=>'Profile0') );
没有成功(firefox启动,但不使用我的配置文件).
我还尝试了黑客创建批处理文件的方法:
#!/bin/bash /usr/bin/firefox -P default
然后开始硒:
java -jar selenium-server-standalone-2.5.0.jar -Dwebdriver.firefox.bin =“/usr/local / src / selenium / myfirefox”
Firefox启动,但不使用默认配置文件,更糟糕的是,一切都挂起来:当以这种方式启动时,硒似乎无法与firefox通信.
附:我看到Selenium – Custom Firefox profile我试过这个:
java -jar selenium-server-standalone-2.5.0.jar -firefoxProfileTemplate "not-there"
而且它拒绝运行!兴奋的,以为我可能在做某事,我试过:
java -jar selenium-server-standalone-2.5.0.jar -firefoxProfileTemplate /path/to/0abczyxw.default/
这什么都不做.即它仍然从一个新的配置文件开始:-(
总结一下他的答复:你把你的firefox档案,拉链(zip,而不是tgz),base64编码,然后发送整个东西作为一个/session json request(把base64字符串放在firefox_profile键的Capabilities对象).
在Linux上执行此操作的一个示例方法:
cd /your/profile zip -r profile * base64 profile.zip > profile.zip.b64
然后如果你在连接时使用PHPWebDriver做:
$webdriver->connect("firefox",array("firefox_profile" => file_get_contents("/your/profile/profile.zip.b64")))
注意:它仍然不会是我的真实个人资料,而不是它的副本.所以书签不会被记住,缓存不会被填充等.
关于如何在Selenium中使用自定义Firefox配置文件?和Java的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Firefox配置文件中的selenium禁用插件、html – 一个Xpath表达式在selenium中不起作用,但在Firefox中有效、javascript – 如何在C#Selenium中向FirefoxDriverService添加配置文件规范?、php – Selenium2 firefox:使用默认配置文件等相关内容,可以在本站寻找。
本文标签: