Question

I have to get the title from a Browser's tab and store it in a string variable. I am working on Ranorex Automation tool and using C# as my scripting language.

Thanks, Mudit

Was it helpful?

Solution

Maybe something like this!!??

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;
using System.Web.Http;
using System.Web;


 namespace HTMLConsoleRead1._0

{

class Program




 { 

    static void Main(string[] args)

     {

        string htmlTitle = File.ReadAllText("masterHTML.html");

        Console.WriteLine(GetTitle(htmlTitle));

        Console.ReadLine();

    }

    static string GetTitle(string file)
    {
        Match match = Regex.Match(file, @"<title>\s*(.+?)\s*</title>");
        if (match.Success)
        {
            return match.Groups[1].Value;
        }
        else
        {
            return "";
        }
    }
}

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top