如何从浏览器选项卡中获取标题?

时间:2014-02-19 11:32:14

标签: c# testing automation automated-tests ranorex

我必须从浏览器的标签中获取标题并将其存储在字符串变量中。我正在使用Ranorex自动化工具并使用C#作为我的脚本语言。

谢谢, Mudit

1 个答案:

答案 0 :(得分:0)

也许是这样的事情!! ??

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 "";
        }
    }
}

}

相关问题