使用Selenium Firefox驱动程序绑定特定IP地址并使用ForceBindIP打开Firefox。

4

我有以下代码。

IWebDriver webDriver = null;

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startinfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "ForceBindIP64.exe";
startInfo.Arguments = " -i 10.1.1.111 \"C:\\Program Files\\Mozilla Firefox\\firefox.exe\"";
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();

System.Uri = new System.Uri("http://localhost:7055/hub");

Thread.Sleep(5000);

webDriver = new RemoteWebDriver(uri, options);

我在这里尝试使用ForceBindIP绑定特定的IP,以及使用selenium Firefox驱动程序(即geckodriver)打开浏览器实例。在webDriver = new RemoteWebDriver(uri, options);处,我遇到以下异常错误。

enter image description here

enter image description here

enter image description here

我理解我得到以上错误可能是因为我定义的端口号可能是错误的,或者我将不得不使用Firefox驱动程序打开浏览器。也可能是其他原因。有人有解决方案吗?我将不得不通过ForceBindIP将由驱动程序打开的浏览器实例绑定到特定的IP。
2个回答

0

使用ForcebindIp无法启动Firefox浏览器,因为Firefox使用系统中第一个活动的IP。由于无法使用focebindip启动驱动程序,因此您可以通过将其他互联网转换为代理并在Firefox中添加代理来使用您的互联网,而不是尝试以这种方式启动它。


0

您可以根据ForceBindIP文档尝试设置此Firefox设置:

Firefox需要将about:config?filter=browser.launcherProcess.enabled首选项设置为false,否则ForceBindIP会附加到启动器而不是实际程序。

根据Selenium网格文档,为了允许所有网格组件之间的通信,应公开几个端口。 您可以使用PowerShell 命令测试连接性。

powershell.exe tnc localhost -port 7055 

在几篇帖子中,我看到hubURL是这样的(在hub之前有wd)。我猜你已经改变了默认端口,也许是URL:

hubUrl = "http://localhost:4444/wd/hub

我不确定这是否适用于你的使用情况,但是你可以连接到已经运行的Firefox实例:
如何使用Selenium(Python)连接到现有的firefox实例
Selenium如何使用/附加现有浏览器?
Selenium webdriver - 如何使用C#连接到由Visual Studio打开的同一Firefox实例


我只是一个中间人,所以并没有资格决定这是否解决了问题;但它展示了研究和链接到官方来源,因此获得了奖励,因为付出了努力创建详细的答案。 - tripleee

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接