priya
priya

Reputation: 45

selenium - locate a href link - Unable to find element with link text

enter image description here

I getting below error - if I use linktext() to locate specifications link

Error :

Unable to find element with link text == Specifications

Upvotes: 0

Views: 1847

Answers (2)

cruisepandey
cruisepandey

Reputation: 29382

The problem is you are using specifications but it is Specifications.
Just with capital S , it should be working fine.

You can use explicit wait, something like :

new WebDriverWait(driver,20).until(ExpectedConditions.elementToBeClickable(By.linkText("Specifications"))).click();  

OR with partial link Text :

 new WebDriverWait(driver,20).until(ExpectedConditions.elementToBeClickable(By.partialLinkText("Specifications"))).click();  

If both of them still are not working, then you can try this xpath :

//td[@class='subtabTxtNsel']/a[text()='Specifications' and @tag='a']  

Your binding language is not specified, I have provided answer in JAVA.

UPDATE :

An explicit wait is code you define to wait for a certain condition to occur before proceeding further in the code. The worst case of this is Thread.sleep(), which sets the condition to an exact time period to wait. There are some convenience methods provided that help you write code that will wait only as long as required. WebDriverWait in combination with ExpectedCondition is one way this can be accomplished

Please refer this link for better understanding.

Upvotes: 0

undetected Selenium
undetected Selenium

Reputation: 193308

As per the HTML you have shared incase linktext() shows error as:

Error : Unable to find element with link text == Specifications

As an alternative you may need to induce WebDriverWait for the desired element to be clickable and you can use either of the following solutions:

  • linkText:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("Specifications"))).click();    
    
  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("td.subtabTxtNsel>a.subtabTxtNsel[tag='a']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//td[@class='subtabTxtNsel']/a[@class='subtabTxtNsel' and contains(.,'Specifications')]"))).click();
    

Upvotes: 1

Related Questions