How to use locators of Selenium for tabs within Angular application

55 Views Asked by At

I am new to Selenium with Java.

As per the requirement I need to access a TAB within my Angular application.

<a _ngcontent-ng-c689374991="" data-val="Dreams" routerlink="/dreams" data-toggle="tab" href="/dreams" role="tab" class="active"><span _ngcontent-ng-c870109355="" class="slanted-text">Dreams</span></a>

Every time I try to locate the TAB, it gives error stating "Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:"

Tried the following ways using xpath, but unable to achieve the result:-

  1. Using Full XPath
driver.findElement(By.xpath("/html/body/app-root/app-top-nav/div/div/div/div[2]/div/div[2]/ul/li[5]/a")).click();
  1. Using XPath
driver.findElement(By.xpath("//*[@id=\"offcanvasExample\"]/div[2]/ul/li[1]/a")).click();
  1. Using Router Link
driver.findElement(By.xpath("//div[@_ngcontent-ng-c870109355-router-link='/dreams']")).click();
  1. Using HREF
driver.findElement(By.xpath("//*[contains(text(), 'href=/dreams')]")).click();

Could someone please guide me?

0

There are 0 best solutions below