
Hi anonymous useraa-2217
If you want to refresh pages in Edge, you can get Edge process first. After that, you can get all the tabs in Edge and set focus to tabs and refresh them by simulating pressing F5
using the System.Windows.Forms.SendKeys.SendWait method.
The sample code is like below:
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Windows.Automation;
namespace refreshEdge
{
class Program
{
static void Main(string[] args)
{
Process[] procsEdge = Process.GetProcessesByName("msedge");
foreach (Process Edge in procsEdge)
{
if (Edge.MainWindowHandle != IntPtr.Zero)
{
AutomationElement root = AutomationElement.FromHandle(Edge.MainWindowHandle);
var tabs = root.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem));
var elmUrl = root.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Address and search bar"));
foreach (AutomationElement tabitem in tabs)
{
if (elmUrl != null)
{
AutomationPattern[] patterns = elmUrl.GetSupportedPatterns();
if (patterns.Length > 0)
{
ValuePattern val = (ValuePattern)elmUrl.GetCurrentPattern(patterns[0]);
string url = val.Current.Value;
Console.WriteLine(url.Contains("bing.com"));
}
}
tabitem.SetFocus();
SendKeys.SendWait("{F5}");
}
}
}
}
}
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Regards,
Yu Zhou