Looking for a solution to invoke Navigation in Chrome from outside of chrome by external process.
We have legacy WinForm Software that needs to browse an Angular HTML5 app that requires Chrome to run. (I have no control of this.)
Something along lines of:
Process process = new Process();
process.StartInfo.FileName =
#"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
process.StartInfo.Arguments = "google.com" + " --new-window";
process.Start();
And then some way to hook into that process and have the SAME TAB perform navigation.
magic.navigateTab1(www.anothersite.com);
I quite assume its not easily possible, solution may not use Process etc.. Just, anyway to accomplish it from outside chrome?
Whatever solution can't require installing > ~5MB to C# code base.. Ideally, no installation is preferred.
http://cefsharp.github.io/ <- looked into this but this is huge.
Edit 1: Perhaps using something like this..
https://sites.google.com/a/chromium.org/chromedriver/
I used Selenium to achieve that.
First you must add via Nugget the following packages to your solution
Selenium.WebDriver
Selenium.Chrome.WebDriver;
Then reference the following namespaces
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
Create the following property on your class root
IWebDriver driver;
On your class constructor add the following code to create a new Chrome Window handled by Selenium
driver = new ChromeDriver();
Then on your buttons add the following
// Switch the action target to the first tab opened on chrome instace handled by Selenium
driver.SwitchTo().Window(driver.WindowHandles.First());
// Go to a given URL
driver.Navigate().GoToUrl("http://www.yourURL.com.br");
Your code should be like that
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace configure
{
public partial class Form1 : Form
{
IWebDriver driver;
public Form1()
{
InitializeComponent();
driver = new ChromeDriver();
}
private void button1_Click(object sender, EventArgs e)
{
driver.SwitchTo().Window(driver.WindowHandles.First());
driver.Navigate().GoToUrl("http://www.yourURL.com.br");
}
}
}
Hope this solve your problem
I'm trying to run some unit tests using Selenium Webdriver and C#.Net for Firefox browser but I was unable to do it (Chrome and IE11 browsers are working smoothly).
Here is the info I gathered:
OS: Windows 10 Enterprise
Gecko driver version: geckodriver-v0.17.0-win32
Mozilla Firefox version: 54.0.1 (32-bit)
Environment Path variable already set under "C:\LEO\SELENIUM C#\Firefox"
Piece of Code:
using System;
using System.Text;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Firefox;
[TestFixture]
public class UnitTest3
{
private IWebDriver driver;
private StringBuilder verificationErrors;
private string baseURL;
[SetUp]
public void SetupTest()
{
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(#"C:\LEO\SELENIUM C#\Firefox");
service.FirefoxBinaryPath = #"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
driver = new FirefoxDriver(service);
baseURL = "http://www.dow.com";
verificationErrors = new StringBuilder();
}
}
Error:
Message: OpenQA.Selenium.WebDriverException : Unable to find a matching set of capabilities.
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
StackTrace:
I will appreciate all your help, thanks.
First of all, you need Firefox: Developer Edition installed and updated.
That`s should be enough in your case.
Source with full guide.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
namespace SeleniumTidBits
{
[TestClass]
public class UnitTest1
{
static IWebDriver driverFF;
static IWebDriver driverGC;
[AssemblyInitialize]
public static void SetUp(TestContext context)
{
driverFF = new FirefoxDriver();
driverGC = new ChromeDriver();
}
[TestMethod]
public void TestFireFoxDriver()
{
driverFF.Navigate().GoToUrl("http://www.google.com");
driverFF.FindElement(By.Id("lst-ib")).SendKeys("Selenium");
driverFF.FindElement(By.Id("lst-ib")).SendKeys(Keys.Enter);
}
[TestMethod]
public void TestChormeDriver()
{
driverGC.Navigate().GoToUrl("http://www.google.com");
driverGC.FindElement(By.Id("lst-ib")).SendKeys("Selenium");
driverGC.FindElement(By.Id("lst-ib")).SendKeys(Keys.Enter);
}
}
}
Error:
Error Image
I'm just trying to run some random scripts to test webdrivers of Selenium. I'm using VS 2012 and i have imported driver from Nuget package.
For starting the test in Firefox, You will have to download geckodriver from here: https://github.com/mozilla/geckodriver/releases and use this code:
System.setProperty("webdriver.firefox.marionette", [path to the driver]);
WebDriver driver = new FirefoxDriver();
That Error states that Selenium WebDriver could not find the Firefox driver in your project folder.
Also, Webdriver no longer supports the default Firefox Driver. They are currently working on a new driver, called Marionette, for their new Gecko engine.(You have the link in the error)
More details on Marionette you can find here: Marionette
If you want to use the default driver, you should downgrade your Firefox. Version 45.0.1 works fine for me. And you should get Selenium Webdriver 2.53, the one you are using is 3.0.0 (The latest from NUget)
I have a strange issue using Selenium Web driver with C#.
When I navigate to this webpage manually in Chrome or using the Firefox Selenium WebDriver then the following "Proovikabiin" link is displayed.
But when using the Chrome WebDriver the button is not displayed.
What in the world would cause this behavior difference? I prefer to keep my tests passing browser agnostic.
[Edit] Software Versions
Selenium.WebDriver, 2.26.0. Installed via NuGet.
Chrome WebDriver, 23.0.1240.0 from
here. The photo showing the button was created from the same chrome instance launched by the web driver, but just copy and pasting the link.
I'm using the built-in Firefox driver. Currently Firefox 17.0.1
installed on computer.
Here's some code.
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
namespace IntegrationMonitorLibrary.WebTests.FailFolder
{
[TestFixture]
class BrowserInconsistancyWithProovikabiinButton
{
[Test]
public void FirefoxShowsButton()
{
IWebDriver driver = new FirefoxDriver();
var url = "http://www.sangar.ee/et/mensshirts/meeste-sark-franco-s310166890.html";
driver.Navigate().GoToUrl(url);
var buttonId = "fitsmebutton";
driver.FindElement(By.Id(buttonId)).Click();
}
[Test]
public void ChromeDoesNotShowButton()
{
IWebDriver driver = new ChromeDriver();
var url = "http://www.sangar.ee/et/mensshirts/meeste-sark-franco-s310166890.html";
driver.Navigate().GoToUrl(url);
var buttonId = "fitsmebutton";
driver.FindElement(By.Id(buttonId)).Click();
}
}
}
I'm working on Automation framework using WebDriver with C#. Its working fine with Firefox but not with IE.
I am getting the following error:
IEDriverServer.exe does not exist-The file c:\users\administrator\documents\visual studio 2010\projects\TestProject1\TestProject1\bin\Debug\IEDriverServer.exe does not exist. The driver can be downloaded at http://code.google.com/p/selenium/downloads/list
I am using IE 9 and Windows 7.
IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://www.google.co.uk");
IWebElement queryBox = driver.FindElement(By.Name("q"));
queryBox.SendKeys("The Automated Tester");
queryBox.SendKeys(Keys.ArrowDown);
queryBox.Submit();
See also .
The IEDriverServer.exe (as well as ChromeDriver.exe) can be downloaded from:
http://selenium-release.storage.googleapis.com/index.html.
To get these to work with your Selenium tests, include the .exe in your test project, and set its properties to 'Copy Always'.
NOTE: You'll have to adjust the Add File dialog to display .exe files.
Doing this will resolve the error.
Here's a simple C# example of how to call the InternetExplorerDriver using the IEDriverServer.exe.
Refactor according to your needs.
Note: the use of driver.Quit() which ensures that the IEDriverServer.exe process is closed, after the test has finished.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.IE;
namespace SeleniumTest
{
[TestClass]
public class IEDriverTest
{
private const string URL = "http://url";
private const string IE_DRIVER_PATH = #"C:\PathTo\IEDriverServer.exe";
[TestMethod]
public void Test()
{
var options = new InternetExplorerOptions()
{
InitialBrowserUrl = URL,
IntroduceInstabilityByIgnoringProtectedModeSettings = true
};
var driver = new InternetExplorerDriver(IE_DRIVER_PATH, options);
driver.Navigate();
driver.Close(); // closes browser
driver.Quit(); // closes IEDriverServer process
}
}
}
Per Jim Evans (who works on IEDriverServer)
The .NET bindings don't scan the %PATH% environment variable for the
executable. That means for the .NET bindings only, the
IEDriverServer.exe is expected to either be found in the same
directory as the .NET bindings assembly, or you must specify the
directory where it can be found in the constructor to the
InternetExplorerDriver class.
Failure to do one of these things (or to
set the UseInternalServer property in the InternetExplorerOptions
class) will cause the .NET IE driver implementation to throw an
exception. This is strictly by design, as we want people to begin
using the standalone IEDriverServer.exe, and the ability to use an
"internal" or "legacy" version of the server will be removed in a
future release.
https://groups.google.com/forum/?fromgroups#!topic/webdriver/EvTyEPYchxE
If you're working with Visual Studio and C# I've updated my NareshScaler nuget package to install IEDriverServer, ChromeDriver etc automatically, meaning you can get up and running quicker.
http://nuget.org/packages/NareshScaler
Code for WebDriver using java to run with IE. I believe this concept might be helpful for you using C#:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
File file = new File("C:\\Program Files\\Internet Explorer\\iexplore.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
driver = new InternetExplorerDriver(capabilities);
If above code doesn't work use the following instead of "File file = new File("C:\Program Files\Internet Explorer\iexplore.exe");":
File file = new File("F:\\Ripon\\IEDriverServer_Win32_2.25.2\\IEDriverServer.exe");
[Note: The version of IEDriverServer and Windows (32 or 64 bit) may vary individual to individual]
Give path only till folder where Internetexplorer.exe is located.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using System.IO;
namespace Automation
{
class To_Run_IE
{
static void Main(string[] args)
{
//Keep Internetexplorer.exe in "D:\Automation\32\Internetexplorer.exe"
IWebDriver driver = new InternetExplorerDriver(#"D:\Automation\32\"); \\Give path till the exe folder
//IWebDriver driver = new Firefoxdriver()
driver.Navigate().GoToUrl("http://www.google.com/");
driver.Manage().Window.Maximize();
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("Cheese");
query.Submit();
System.Console.WriteLine("Page title is: " + driver.Title);
driver.Quit();
}
} }
public IWebDriver IEWebDriver()
{
var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
webDriver = new InternetExplorerDriver(ConfigurationSettings.AppSettings["IDEServerPath"].ToString(), options);//Path of ur IE WebDriver,Here I stored it in a AppConfig File
return webDriver;
}