[英]open a local html file from web browser control in microsoft edge instead of internet explorer
[英]Send data to a website using Microsoft Edge (switching from Internet Explorer)
我有这个用 C# 编写的现有 Windows 窗体应用程序,它处理数据并将处理的数据发送到网站。
它在 Internet Explorer 中运行良好,但我希望它也能在 Microsoft Edge 上运行。 可以使用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();
}
}
}
}
我检查了你的代码,看起来你正试图在你的代码中自动化 IE 浏览器。
您不能为 Edge 浏览器运行相同的代码。
我建议您尝试使用Microsoft Web 驱动程序使用 c# 代码自动化 MS Edge 浏览器。
这是一个代码示例:
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();
}
}
}
参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.