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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.