sethjbr
sethjbr

Reputation: 125

C# Using Selenium with Chrome Portable and driver.Navigate().GoToUrl

What I am trying to accomplish is, I think, relatively simple. I am trying to write code that will use a Google Chrome Portable executable and also execute selenium powered web-page element finding and selecting using the latest version of the chrome driver. Currently, I know how to do one or the other, but not both.

The following code will open Google Chrome from it's standard installation location (C:Program Files (x86) and input the text for "Polar Bears" in the Google Search box.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;

namespace LaunchChrome
{
    class GoogleInquiry
    {
        static void Main(string[] args)
        {
            //Start Chrome Driver Service from Custom Location
                ChromeDriverService service = ChromeDriverService.CreateDefaultService(@"C:\GoogleSearch");

            //Force the CMD prompt window to automatically close and suppress diagnostic information
                service.HideCommandPromptWindow = true;
                service.SuppressInitialDiagnosticInformation = true;

            //Setup Chrome to utilize custom options
                var options = new ChromeOptions();

            //Google Chrome Custom Options
                options.AddArgument("disable-infobars");
                options.AddArgument("--silent");

            // Assign driver variable to Chrome Driver            
            var driver = new ChromeDriver(service, options);

            //Navigate to the Google website
                driver.Navigate().GoToUrl("https://www.google.com");

            //Automate custom Google Search Submission
                driver.FindElement(By.Name("q")).SendKeys("Polar Bears");

        }
    }
}

But, when I use the custom chrome location binary option given below, than it will open Google Chrome Portable, but it won't go to google.com. Rather, the URL will say simply "data:," and the code will timeout in visual studio with this message:

"OpenQA.Selenium.WebDriverException: 'The HTTP request to the remote WebDriver server for URL http://localhost:59127/session timed out after 60 seconds.'

options.BinaryLocation = @"C:\GoogleChromePortable\GoogleChromePortable.exe";

I have tried using the chromium flag for new window (-- new-window + URL) and using the app flag (--app +URL) but both fail to run the code that should go to google and input "Polar Bears" in the search box.

Assistance would be appreciated.

Thank you very much.

Seth

For Specs, I am using the following:

Upvotes: 3

Views: 5953

Answers (3)

sethjbr
sethjbr

Reputation: 125

I know this is an old question, but the answer that I found to this question was that if I copy the Google Chrome enterprise installation files to an alternate location on the computer, then point the code to the chrome.exe binary absolute location, than it works.

Upvotes: 1

Eid3r
Eid3r

Reputation: 49

You should use the other chrome.exe location the one which is inside Chrome-bin folder

String seStandAloneServerUrl = @"the stand alone server url here";
var cOptions = new ChromeOptions();
cOptions.BinaryLocation = @"C:\GoogleChromePortable\App\Chrome-bin\chrome.exe";
driver = new RemoteWebDriver(new Uri(seStandAloneServerUrl), cOptions);

Upvotes: 4

undetected Selenium
undetected Selenium

Reputation: 193128

As per your question and code attempts I don't see any any major flaw. Perhaps as per other discussions options.BinaryLocation must point to the absolute location of the portable chrome binary as follows:

options.BinaryLocation = @"C:\\GoogleChromePortable\\chrome.exe";

Upvotes: 0

Related Questions