Search code examples
seleniumselenium-webdriverpage-factory

How to read text inside <title> tag using Selenium and Java?



I've got some webpage and I'm looking for title tag with FindBy annotation (PageFactory.initElements is present in constructor of the class):

@FindBy(tagName = "title")
private WebElement titleTag;

After that I'm trying to get "some text" with WebElement method titleTag.getText(). The part of HTML code is common: <title>some text</title>. But I got absolutely no output - literally. Have tried to compare result with null, "", \n and even \0 - it's always false comparation.


Solution

  • There is no need to use @findBy for this. Just use driver.getTitle()