Unable to click on link - no element found exception using Java selenium webdriver



  • 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>
    


  • 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();
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2