如何使用 Selenium Webdriver (C#) 获取页面名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13472026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 08:42:05  来源:igfitidea点击:

How to get a page name using Selenium Webdriver (C#)?

c#seleniumselenium-webdriver

提问by user1838551

How can I get page title using Selenium C# Webdriver?

如何使用 Selenium C# Webdriver 获取页面标题?

回答by DevDave

Or I think that

或者我认为

driver.Title;

also works?

也有效?

回答by Robert L.

driver.Title is the easy way to get the title of the page. It returns a string.

driver.Title 是获取页面标题的简单方法。它返回一个字符串。

string myTitle = driver.Title;

If you want the title as an IWebElement then you can also get it by searching the DOM.

如果您希望标题作为 IWebElement,那么您也可以通过搜索 DOM 来获取它。

IWebElement myTitle = driver.FindElement(By.TagName("title"));

回答by PD Mohanty

You can get the title of the page by using: -driver.Title;

您可以使用以下命令获取页面标题: -driver.Title;

Below i have written a small test that can help you understand how it works..

下面我写了一个小测试,可以帮助您了解它是如何工作的。

public void someTest()
{
 driver.Navigate().GoToUrl("http://google.com");
 String title=driver.Title;
}