At the time of writing Microsoft Edge is not supported by CodedUI, they have mentioned they are evaluating support but currently you can't use it: This link shows a filed bug on the issue: https://connect.microsoft.com/VisualStudio/feedback/details/1551238/vs2015-supports-codedui-automation-test-for-edge-browser
WebDriver is the currently the best way to do automation of Microsoft Edge. However looking at the code above you are not able to do exactly the same thing. With WebDriver you can locate an element by Id, ClassName, TagName, Name, LinkText, Partial Link Text, CSS, Xpath but as far as I am aware you can't locate an object from x, y co-ordinates as you do in the example above.
To get started with Webdriver. Create a console app. Install the following packages:
Install-Package Selenium.RC
Install-Package Selenium.WebDriver
Install-Package Selenium.WebDriverBackedSelenium
Install-Package Selenium.Support
Install The correct Microsoft WebDriver depending on your operating system:
More Information on Microsoft WebDriver can be found here.
You can then add some code to drive WebDriver, the following example goes to my blog and gets an element via it's css class name:
using System;
using System.IO;
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
namespace SampleGetText
{
public class Program
{
static void Main(string[] args)
{
var text = GetText();
}
public static string GetText()
{
RemoteWebDriver driver = null;
string serverPath = "Microsoft Web Driver";
// Makes sure we uses the correct ProgramFiles depending on Enviroment
string programfiles = Environment.Is64BitOperatingSystem ? "%ProgramFiles(x86)%" : "%ProgramFiles%";
try
{
// Gets loaction for MicrosoftWebDriver.exe
serverPath = Path.Combine(System.Environment.ExpandEnvironmentVariables(programfiles), serverPath);
//Create a new EdgeDriver using the serverPath
EdgeOptions options = new EdgeOptions();
options.PageLoadStrategy = EdgePageLoadStrategy.Eager;
driver = new EdgeDriver(serverPath, options);
//Set a page load timeout for 5 seconds
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(5));
// Navigate to my blog
driver.Url = "https://blogs.msdn.microsoft.com/thebeebs/";
// Find the first element on my screen with CSS class entry-title and return the text
IWebElement myBlogPost = driver.FindElement(By.ClassName("entry-title"));
return myBlogPost.Text;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return "";
}
finally
{
if (driver != null)
{
driver.Close();
}
}
}
}
}