如何从Selenium Webdriver获取网页标题? [英] How to get the web page title from selenium webdriver?

查看:70
本文介绍了如何从Selenium Webdriver获取网页标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是用于从驱动程序打开的浏览器获取实际标题的代码.

Below is the code used for getting the actual title form the Driver opened browser.

public class imsclass1 {
    WebDriver driver;
    String actualTitle;

    @Test
    public void test() {
        driver.get("http://www.google.com");
        actualTitle = driver.get actualTitle();
        System.out.println("ActualTitle is +");
    }

    @BeforeClass
    public void Beforeclass() {
        driver = new FirefoxDriver();
    }

    @AfterClass
    public void Afterclass() {
        driver.quit();
    }
}

输出显示为实际标题是

我想要的是在浏览器中显示网页标题".它需要在我的控制台中打印.

What I want is "Web page title" displayed in the browser. It needs to be get printed in my console.

推荐答案

要获取页面标题,请使用驱动程序的 getTitle()方法.

To get the page title use getTitle() method of driver.

actualTitle = driver.getTitle();

这篇关于如何从Selenium Webdriver获取网页标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆