-1

I'm trying to perform a click action on the "sign out" link on Gmail but my console keep saying that it's unable to locate the element. Below is my code.Thank you!

@FindBy(linkText="Sign out")
WebElement logoutLink;

This is the HTML:

enter image description here

And this is the WebElement:

https://i.sstatic.net/JI9r6.png

2 Answers 2

0

If you observe closely the text Sign out is actually within a <div> which have an ancestor <span> which again have an ancestor <a>

So an effective locator strategy can be:

  • Using xpath:

    @FindBy(xpath="//a//span//div[text()='Sign out']")
    WebElement logoutLink;
    
Sign up to request clarification or add additional context in comments.

Comments

0

You can use this XPath to locate that element:

"//a[contains(@href,'Logout')]"

Or this CSS Selector:

"a[href*='Logout']"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.