Click function is not triggering even after button is clicked using htmlunit driver



  • I am able to click submit button and submit button click is working fine but text entered to add comments is not showing (basically submit button click is working ,but submit button functionality is not triggering 😞

    DOM:

    <div _ngcontent-sfd-c33="" class="d-flex marg-top-2 ng-star-inserted">
        <button _ngcontent-sfd-c33="" class="marg-start-auto btn btn-secondary" type="button"> Cancel </button>
        <button
    _ngcontent-sfd-c33="" class="btn marg-start-1 btn-primary" type="button">
            <span _ngcontent-sfd-c33=""></span>
            <adapt-busy-backdrop class="ng-tns-c8-21 ng-star-inserted"></adapt-busy-backdrop>
            <adapt-busy class="ng-star-inserted">
                <ng-component class="ng-tns-c10-23 ng-star-inserted"></ng-component>
            </adapt-busy>
            <span _ngcontent-sfd-c33="" class="ng-star-inserted">Submit</span>
        </button>
    </div>
    

    Here is my code :

    WebElement submit = driver.findElement(By.xpath("(.//*[normalize-space(text()) and normalizespace(.)='Cancel'[1]/following::span[2]"));
    String submitButton = "arguments[0].style.height='auto';arguments[0].style.visibility='visible';";
    ((JavascriptExecutor) driver).executeScript(submitButton, submit);   
    submit.click(); 
    

    enter image description here



  • You should be clicking the Button tag and not the span tag, please use the below locator:

    WebElement submit = driver.findElement(By.xpath("//span[contains(text(),'Submit')]/..")
    


Suggested Topics

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