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

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.