使用 Java 与 Selenium WebDriver 获取页面标题。
我们可以使用 Selenium WebDriver 获取页面标题。方法 getTitle() 用于获取当前页面标题,然后我们可以在控制台中获取结果。
语法
t = driver.getTitle();
让我们查找当前页面的标题。我们将获得 关于 Tutorials Point 的职业生涯 – Tutorialspoint 作为输出。

示例
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class PageTitle{
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("https://tutorialspoint.com/about/about_careers.htm");
// getTitle() to obtain page title
System.out.println("Page title is : " + driver.getTitle());
driver.close();
}
}输出

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP