3

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:

  • Windows 7
  • Visual Studio Community Edition 2017
  • Google Chrome Portable 68 (Also tried older versions of Chrome portable)
  • Chrome Driver 2.40 (also tried 2.41)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
sethjbr
  • 125
  • 2
  • 11

3 Answers3

4

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);
Eid3r
  • 41
  • 4
1

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.

sethjbr
  • 125
  • 2
  • 11
0

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";
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Thank you @DebanjanB for your efforts. I really appreciate it. However, using the absolute location and also renaming the default "GoogleChromePortable.exe" to simply "chrome.exe" yields the same result. :( The webpage URL still simply says just "data:,". – sethjbr Aug 08 '18 at 16:50
  • I also tried the python code that you linked and it also fails to load the website. Google Chrome just sits there with "data:," in the URL and a blank CMD window is open. Any other suggestions? – sethjbr Aug 08 '18 at 17:01