overdd
overdd

Reputation: 99

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.

Upvotes: 1

Views: 1343

Answers (1)

mkhurmi
mkhurmi

Reputation: 816

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

Upvotes: 1

Related Questions