Hi guys in this post we are to see "How to Print all the Links Text from Webpage" using Coded UI
In this example :
- Opening browser and navigating to http://automationplace.blogspot.in
BrowserWindow bw = BrowserWindow.Launch("www.automationplace.blogspot.com");
2. Assigning the Webcontrol to UITestControl
UITestControl links = new UITestControl(bw);
links.TechnologyName
= "web";
links.SearchProperties.Add("Controltype", "Hyperlink");
3. Loop all the links.
foreach(UITestControl alllinks in links.FindMatchingControls())
{
Console.WriteLine("All links " +
alllinks.GetProperty("Innertext"));
}
Source Code :
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Input;
using System.Windows.Forms;
using System.Drawing;
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UITest.Extension;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
namespace CodedUIDemo2
{
/// <summary>
/// Summary description for CodedUITest1
/// </summary>
[CodedUITest]
public class CodedUITest1
{
public CodedUITest1()
{
}
[TestMethod]
public void Printlinks()
{
BrowserWindow bw = BrowserWindow.Launch("www.automationplace.blogspot.com");
UITestControl links = new UITestControl(bw);
links.TechnologyName = "web";
links.SearchProperties.Add("Controltype", "Hyperlink");
foreach(UITestControl alllinks in links.FindMatchingControls())
{
Console.WriteLine("All links
" + alllinks.GetProperty("Innertext"));
}
}
}
}
You will see all the hyperlink present in webpage.
Hope you Like this post.
hi prashant
ReplyDelete1>Is thier any logic to wait for perticuler element untill it appears?
2>give me some verification scripts like assertTrue,assertEqules like that
i am newer to C#
ReplyDelete