Selenium WebDriver - No driver is working for me

2020-04-11 10:31发布

问题:

I'm trying to get Selenium tests running. I'm using C#. I'm having a problem with every driver I tried.

Chrome

var options = new OpenQA.Selenium.Chrome.ChromeOptions();
options.BinaryLocation = @"C:\Users\Vilem\AppData\Local\Google\Chrome\Application\";

using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(options))
{
...

Seems like chromedriver.exe was found but it could find the Chrome binary. I set up the path to chrome.exe explicitly after automatic search failed. I even tried it with "chrome.exe" at the end. I always get the same result:

Could not find Chrome binary at:

C:\Users\Vilem\AppData\Local\Google\Chrome\Application

Firefox

new OpenQA.Selenium.Firefox.FirefoxDriver();

I also tried it with a profile set:

FirefoxProfile profile = new FirefoxProfile(@"E:\...\FirefoxProfile"); 
new OpenQA.Selenium.Firefox.FirefoxDriver();

Error I'm getting:

Unable to bind to locking port 7054 within 45000 ms

IE

var ieOptions = new InternetExplorerOptions();
ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
new InternetExplorerDriver(@"C:\Program Files (x86)\IEDriver\", ieOptions);

The folder with the driver is also set in PATH.

The error I'm getting:

No response from server for url http://localhost:6955/session

Is there something I'm missing? I would be happy if any of them got working.

Thanks

回答1:

I got Chrome and IE working by putting the .exe for ChromeDriver and IE_driver in the project /bin/ folder

Ex.

VisualStudio2010/Projects/ProjName/ProjName/bin/chromedriver.exe

Then when setting up my tests I did:

using OpenQA.Selenium.Chrome;
...
private IWebDriver chrome;
...
[SetUp]
public void SetupTest()
    {
        chrome= new ChromeDriver();
        baseURL = "url-goes-here";
        verificationErrors = new StringBuilder();
    }
...

You can download the .exe from here if you haven't already



回答2:

Chrome

Could not find Chrome binary at:
C:\Users\Vilem\AppData\Local\Google\Chrome\Application

I think you have to specify the whole path including the executable. Like C:\Users\Vilem\AppData\Local\Google\Chrome\Application\chrome.exe (just guessing, have currently no access to a Windows machine)

Firefox

Unable to bind to locking port 7054 within 45000 ms

You should not get that permanently. Quickest solution to tell you without asking a lot of questions back: Restart (or logout-login). If you still get that after reboot, have a look at questions about it and maybe post your own.



回答3:

You should specify the path including .exe. So, your code would be as follows:

options.BinaryLocation = @"C:\Users\Vilem\AppData\Local\Google\Chrome\Application\chrome.exe";
new InternetExplorerDriver(@"C:\Program Files (x86)\IEDriver\iexplore.exe", ieOptions);