I am using Selenium webdriver with Java. I need to click on link - Register New Consumer.

HTML:

<a href="/int/cdms/registrationType.do" target="_self">Register
        New Consumer<br>
            </a>

I tried using xpath, css, linktext, partiallinktext, wait etc but nothing seems to work and all comes with No Element found exception.

Code:

driver1.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver1.findElement(By.cssSelector(".formtable > tbody:nth-child(1) >
tr:nth-child(2) > td:nth-child(1) > a:nth-child(1)")).click();

Complete HTML Code:

<table class="formtable">
   <tbody>
      <tr>
         <td>
         </td>
      </tr>
      <tr>
         <td>
            <a href="/int/cdms/registrationType.do" target="_self">Register
            New Consumer<br>
            </a>
         </td>
      </tr>
      <tr>
         <td>
            <a href="/int/cdms/amendSearch.do" target="_self">Amend Consumer
            Details<br>
            </a>
         </td>
      </tr>
      <tr>
         <td>
            <a href="/int/cdms/inquirySearch.do" target="_self">Inquire on
            Consumer Details<br>
            </a>
         </td>
      </tr>
      <tr>
         <td>
            <a href="/int/cdms/deleteSearch.do" target="_self">Delete Consumer<br>
            </a>
         </td>
      </tr>
      <tr>
         <td>
            <a href="/int/cdms/resolveProvisionalConsumer.do" target="_self">Resolve
            Provisional IHI<br>
            </a>
         </td>
      </tr>
      <tr>
         <td></td>
      </tr>
      <tr>
         <td></td>
      </tr>
      <tr>
         <td>
         </td>
      </tr>
      <tr>
         <td>
         </td>
      </tr>
      <tr>
         <td>
         </td>
      </tr>
      <tr>
         <td>
         </td>
      </tr>
      <tr>
         <td>
         </td>
      </tr>
      <tr>
         <td>
         </td>
      </tr>
      <tr>
         <td><br>
         </td>
      </tr>
      <tr>
         <td>
         </td>
      </tr>
</table>
  • Your selector looks fine. Check if your table is in iframe. – Alexey R. Sep 14 at 10:33
  • its not in iframe – Taj Sep 17 at 21:52

Use Correct XPath to locate "Register New Consumer" Link.

XPath:

"//a[contains(text(),'Register New Consumer')]"

Add Explicit Wait till element to be Clickable condition:

WebElement eleNewCust_Link = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(text(),
'Register New Consumer')]")));

eleNewCust_Link.click();
  • Let me know if it works for you. – Bharat Mane Sep 14 at 5:25
  • Hi Bharat Thanks for response, however still got selenium - no element found exception – Taj Sep 17 at 3:26
  • Kindly help all as I am stuck and hit a dead wall – Taj Sep 17 at 3:26
  • Okay, let's go through the good old checklist: Are your WebDriver and Element within the same context? Are you sure your element has been loaded before you start your test? What's the last element you can locate by climbing up the HTML tree? Have you checked that the error is thrown at the point you think it's thrown? If all of those are true consider using the JavascriptExecutor. It's not a nice solution but a lot less fickle than the WebDriver. – godisalie92 Oct 15 at 13:12

Use CSS Selector:

driver1.findElement(By.cssSelector("a[href='/int/cdms/registrationType.do']")).click(); 

If you have used css, linktext, partiallinktext, wait etc but nothing seems to work.You can use xpath that we usually use in test automation services.

//a[text()='Register New Consumer']


//a[contains(text(),'Register New Consumer')]

Hope with this issue will get resolved. Further, if you still face the issue you can provide webdriver wait for the presence of or element to be clickable.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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