0

The Context:

I'm using selenium in java to click on a link to navigate to the other page of the application.

The Problem:

The application is made in angular-js wherein I tried to click on the Link, but strange it logs out me directly.

But if I hit the same URL manually, after login it works fine. I'm not sure Where I'm having a mistake here.

The link I'm trying to click

<a data-match-route="/about" ui-sref="about" href="#/about" class="active">About</a>

tried and tested but not working Locators:

driver.findElement(By.xpath("//a[@href='#/about']")

driver.findElement(By.xpath("//a[.='About']")

As soon as the URL is hit, it logs me out with a URL as

https: MY_HOST_URL/login.html#about

Not sure why and how login.html gets appended here.

I even tried to hit the full URL after login through the script but again it redirects to the same URL as

https://MY_HOST_URL/login.html#about
  • Have you tried with the class of the element? Can you share the code, please. – Nikolay Barakov May 8 at 13:22
1

It seems that another element is located and clicked, thus the log out. Try cssSelector:

By.cssSelector("a[ui-sref='about']")

I would suggest to test it in chrome devtools console like this:

$$("a[ui-sref="about]")

This is equivalent of document.querySelectAll so if it returns more then one element the locator is still not valid and you will have to be more specific. In such case posting more html code here can help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.