我有这个用 C# 编写的现有 Windows 窗体应用程序,它处理数据并将处理后的数据发送到网站。
它在 Internet Explorer 中运行良好,但我希望它也可以在 Microsoft Edge 上运行。可以使用边缘吗?
这是我的代码。
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();
}
更新
我目前正在使用 Selenium 并且我尝试使用 Edge 驱动程序它返回给我一个错误
附加信息:向远程 WebDriver 服务器发送 HTTP 请求以获取 URL http://localhost:58191/session时,引发了具有空响应的异常。异常状态为 ReceiveFailure,消息为:底层连接已关闭:接收时发生意外错误。
但是当我尝试使用 firefoxDriver 时它正在工作,但我需要使用现有的 Firefox 打开浏览器会话(现有的打开的 Firefox)。
Selinium webdriver 3.141.0
Microsoft Edge 41.16299.1480.0 - browser
Selenium.webdriver.microsoftdrivere 17.17134.0
OS Windows 10
这是我最新的代码
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();
}
}
}
}