Reputation: 242
I have this existing Windows form application written in C# that processes data and send the proccessed data to a website.
It is working fine in internet explorer but I want to it also to work on Microsoft Edge. is it possible to use Edge?
Here's my code.
private void SendDataToSPC(SHDocVw.InternetExplorer ie, string strSPCData)
{
mshtml.IHTMLDocument3 doc = ie.Document as mshtml.IHTMLDocument3;
mshtml.IHTMLElementCollection txtBoxes = doc.getElementsByTagName("INPUT");
string[] data = Regex.Split(strSPCData, "\r\n");
int intCtr = 0;
foreach (mshtml.IHTMLElement txtBox in txtBoxes)
{
if (txtBox.getAttribute("className") != null)
{
if (txtBox.getAttribute("className").Equals("vcs_de_textbox") && intCtr < data.Length)
{
txtBox.setAttribute("value", data[intCtr]);
intCtr++;
}
}
}
foreach (mshtml.IHTMLElement button in txtBoxes)
{
if (button.getAttribute("className") != null)
{
if (button.getAttribute("className").Equals("vcs_de_saveButton")){
button.click();
}
}
}
((mshtml.HTMLDocument)doc).focus();
}
Update
I currently using Selenium and I try to use Edge driver it returns me an error of
Additional information: A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:58191/session. The status of the exception was ReceiveFailure, and the message was: The underlying connection was closed: An unexpected error occurred on a receive.
But when I try to use firefoxDriver it is working but I need to use existing Firefox open browser session (existing open Firefox).
Selinium webdriver 3.141.0
Microsoft Edge 41.16299.1480.0 - browser
Selenium.webdriver.microsoftdrivere 17.17134.0
OS Windows 10
Here's my latest code
private void SendDataToSPC2(string strSPCData)
{
//Create the reference for our browser
//System.setProperty("webdriver.edge.driver");
//IWebDriver driver = new FirefoxDriver();
//Navigate to google page
//driver.Navigate().GoToUrl("http:www.google.com");
//Find the Search text box UI Element
//IWebElement element = driver.FindElement(By.Id("p1d1"));
//Perform Ops
//element.SendKeys("executeautomation");
//Close the browser
// driver.Close();
IWebDriver edgeDriver = new EdgeDriver();
edgeDriver.Navigate().GoToUrl("http://phgcubadm1ms023/spc/jsp/dataentry/vcsdataentry/vcsDataEntryMain.action");
var txtBoxes = edgeDriver.FindElements(By.TagName("INPUT"));
string[] data = Regex.Split(strSPCData, "\r\n");
int intCtr = 0;
foreach (IWebElement txtbox in txtBoxes)
{
if (txtbox.GetAttribute("className") != null)
{
if (txtbox.GetAttribute("className").Equals("vcs_de_textbox") && intCtr < data.Length)
{
txtbox.SendKeys(data[intCtr]);
intCtr++;
}
}
}
foreach (IWebElement button in txtBoxes)
{
if (button.GetAttribute("className") != null)
{
if (button.GetAttribute("className").Equals("vcs_de_saveButton"))
{
button.Click();
}
}
}
}
Upvotes: 1
Views: 2335
Reputation: 11335
I checked your code and looks like you are trying to automate IE browser in your code.
You cannot run this same code for the Edge browser.
I suggest you try to use Microsoft Web driver to automate MS Edge browser using c# code.
Here is a code example:
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;
using System;
namespace EdgeDriverTests
{
public class Program
{
/*
* This assumes you have added MicrosoftWebDriver.exe to your System Path.
* For help on adding an exe to your System Path, please see:
* https://msdn.microsoft.com/en-us/library/office/ee537574(v=office.14).aspx
*/
static void Main(string[] args)
{
/* You can find the latest version of Microsoft WebDriver here:
* https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
*/
var driver = new EdgeDriver();
// Navigate to Bing
driver.Url = "https://www.bing.com/";
// Find the search box and query for webdriver
var element = driver.FindElementById("sb_form_q");
element.SendKeys("webdriver");
element.SendKeys(Keys.Enter);
Console.ReadLine();
driver.Quit();
}
}
}
References:
Upvotes: 1