问题描述
我正在尝试使用Firefox启动特定的URL.但是我只能打开Firefox浏览器,而不能启动该URL.
I'm trying to launch a specific URL using Firefox. But I'm only able to open Firefox browser and not able to launch that URL.
class BrowserHelper
{
IWebDriver driver;
string path = Path.Combine(Environment.CurrentDirectory, @"gecko\\");
public void Navigate(string url)
{
path = path.Replace(@"\", @"\\");
var driverService = FirefoxDriverService.CreateDefaultService(path);
driverService.HideCommandPromptWindow = true;
if (driver == null)
{
driver = new FirefoxDriver(driverService);
}
driver.Url = url;
driver.Navigate().GoToUrl(driver.Url);
driver.Manage().Window.Maximize();
}
}
class Realtest
{
BrowserHelper BH = new BrowserHelper();
public void test()
{
string search ="apple";
BH.Navigate("https://www.google.com/search?q=" + search);
}
}
我只能获得此页面:
And I can only get this page:
这是我要启动的最终URL: https://www.google. com.sg/search?q=apple
Here's the final URL I want to launch: https://www.google.com.sg/search?q=apple
有什么建议吗?预先感谢.
Any suggestions? Thanks in advance.
推荐答案
我尝试了以下代码(在Java中),并且通过启动浏览器并加载URL也可以正常工作.
I have tried the below code (in Java), and it's working fine by launching the browser and loading the URL also.
System.setProperty("webdriver.gecko.driver","Drivers/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com.sg/search?q=apple");
所以我认为问题出在本地计算机上,安装了geckodriver版本和FireFox浏览器.我建议您将FireFox和geckodriver更新到最新版本.
So I feel the problem is with geckodriver version and FireFox browser installed in your local machine. I would suggest you update FireFox and geckodriver to the latest version.
这篇关于如何在C#中使用Firefox启动特定的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!