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)