我使用Java代码中的Selenium在Firefox中打开Web应用程序。但是我遇到了Firefox配置文件的问题,因为当我运行代码时,Firefox窗口使用新的配置文件打开,所以Web应用程序无法打开,因为代理设置不同(我应该将IP地址添加到Firefox中,无代理IP) 。我尝试从我的代码中获取默认配置文件,但没有任何更改。我也尝试创建新的配置文件,但我不知道如何将IP添加到它。 我改变了代码,所以我可以手动打开Firefox,然后Selenium在nee标签中打开应用程序,所以IP将在那里。但是这也失败了,代码仍然打开新窗口。 如果有人能帮忙,我会非常感激。Selenium:使用java代码打开Firefox,并使用默认配置文件
回答
我们可以用代理值创建一个firefox配置文件,并用该配置文件打开firefox实例。下面的代码可能会给一些想法。
public static void main(String[] args)
{
// Create proxy class object
Proxy p=new Proxy();
// Set HTTP Port to 7777
p.setHttpProxy("localhost:7777");
// Create desired Capability object
DesiredCapabilities cap=new DesiredCapabilities();
// Pass proxy object p
cap.setCapability(CapabilityType.PROXY, p);
System.setProperty("webdriver.gecko.driver", "//PATH");
WebDriver driver=new FirefoxDriver(cap);
}
希望这会有所帮助。谢谢。
你能解释一下端口7777指的是什么?我在哪里可以设置服务器IP地址? –
本地主机是服务器IP地址。如果没有代理然后离开它。所以它看起来像p.setHttpProxy(“172.17.95.1”); –
现在正在工作。非常感谢! –
由于您必须使用GeckoDriver才能使用最新的Firefox,因此您可以使用此设置在firefox中为geckodriver设置代理。
String PROXY = "localhost";
int PORT = 8080;
JSONObject json = new JsonObject();
json.addProperty("proxyType", "MANUAL");
json.addProperty("httpProxy", PROXY);
json.addProperty("httpProxyPort", PORT);
json.addProperty("sslProxy", PROXY);
json.addProperty("sslProxyPort", PORT);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("proxy", json);
GeckoDriverService service =new GeckoDriverService.Builder(firefoxBinary)
.usingDriverExecutable(new File("path to geckodriver"))
.usingAnyFreePort()
.usingAnyFreePort()
.build();
service.start();
// GeckoDriver currently needs the Proxy set in RequiredCapabilities
driver = new FirefoxDriver(service, cap, cap);
- 1. Selenium2 firefox:使用默认配置文件
- 2. 在python中使用selenium webdriver默认的firefox配置文件
- 3. 在Selenium中使用privatebrowsing打开Firefox配置文件
- 4. 无法打开我想设置在Java如下因素代码的Firefox默认的配置文件在Firefox
- 5. 无法使用配置文件(不是临时的)使用Selenium打开Firefox
- 6. selenium python:在歌剧中打开默认配置文件
- 7. 使用Webdriverjs Selenium加载默认Chrome配置文件
- 8. 如何使用Selenium 2 Webdriver打开指定的配置文件Firefox?
- 9. 在终端中打开多个Firefox配置文件并保留默认配置文件
- 10. 当Firefox不是默认浏览器时,使用Firefox打开HTML文件
- 11. 用默认代码打开VIM
- 12. 在Java中使用默认程序打开文件的问题
- 13. 如何设置Selenium以使用多个Firefox配置文件?
- 14. Selenium WebDriver无法打开Firefox配置文件
- 15. 使用java打开文件并追加
- 16. 配置Selenium 2(WebDriver),使用IE并使用WebDriver上传文件
- 17. 使用默认文件浏览器打开文件夹
- 18. 使用硒,无法使用已保存的配置文件打开Firefox
- 19. Selenium/Webdriver:使用现有的Firefox配置文件?
- 20. 如何在Selenium C#中使用现有的Firefox配置文件?
- 21. 从activemq.xml文件读取代理配置并使用Java代码启动代理
- 22. 使用Python使用默认应用程序打开文件,然后在文件打开后打印?
- 23. 使用Delphi代码设置默认打印机终端服务
- 24. 我可以使用getResource打开chromedriver.exe(FireFox/IE)吗? * Selenium-Java
- 25. Selenium:用Java打开下载的文件
- 26. CreateProcessAsUser:如何使用默认应用程序打开文件?
- 27. 在Android中使用默认应用打开文件
- 28. WP7 - 使用默认应用打开文件?
- 29. 使用iOs上的默认应用程序打开文件
- 30. C#Selenium WebDriver FireFox配置文件 - 使用代理与身份验证
什么是您使用的代码和错误是什么。请在问题陈述中添加这些内容。 – demouser123
你需要打开一个处理代理 –
@LM.O的个人资料的Firefox,你可以考虑显示你的工作吗?谢谢 – DebanjanB