How to handle disable button?



  • In my script below code when Thread.sleep() is not used, then it throws an exception "element click intercepted: Element is not clickable at point (226, 567).

    When using the Thread.sleep() it runs and clicks on the Next button, but the problem is that in my application total 9 times next button should be clicked.

    For that I printed message on the log so here only 6 times message gets printed ('btn50-400clicked') and then next button is disabled and unable to proceed to next code.

    Even after waiting for up to 30 minutes it's not working.

    How do I resolve it?

    var next=WDS.browser.findElement(pkg.By.xpath("//button[contains(@class,'btn btn-sm btn-light border ml-3')]"))
    

    while(next.isEnabled())
    {
    java.lang.Thread.sleep(9000);
    //var wait15=new org.openqa.selenium.support.ui.WebDriverWait(WDS.browser, 20000)
    //wait15.until(org.openqa.selenium.support.ui.ExpectedConditions.invisibilityOfElementLocated(pkg.By.xpath("//button[contains(@class,'btn btn-sm btn-light border ml-3')]")))
    var wait9 =new org.openqa.selenium.support.ui.WebDriverWait(WDS.browser, 9000)
    wait9.until(org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable(pkg.By.xpath("//button[contains(@class,'btn btn-sm btn-light border ml-3')]"))).click()
    //next.click();
    WDS.log.info('btn50-400clicked')

            }
            WDS.log.info('btn2clicked')
            //java.lang.Thread.sleep(3000);
            if(!next.isEnabled()){
                           WDS.log.info('Next button disabled')}
    



  • I fail to see where you're updating the value of the next variable so my expectation is that at some point when the button is disabled the loop is still running.

    So my expectation is that you need to change this line:

    wait9.until(org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable(pkg.By.xpath("//button[contains(@class,'btn btn-sm btn-light border ml-3')]"))).click()
    

    to these:

    next = wait9.until(org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable(pkg.By.xpath("//button[contains(@class,'btn btn-sm btn-light border ml-3')]")))
    next.click()
    

    Also you can try taking screenshots and capturing the https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model in case of failure, this way you will get the full picture regarding what went wrong, i.e. put your code into a https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch like:

    var exception = null
    

    try {
    //your code here
    } catch (err) {
    WDS.log.error(err.message)
    WDS.log.error('Page source: ' + WDS.browser.getPageSource())
    var screenshot = WDS.browser.getScreenshotAs(pkg.OutputType.FILE)
    screenshot.renameTo(new java.io.File('screenshot.png'))
    exception = err
    } finally {
    throw (exception)
    }

    More information: https://www.blazemeter.com/blog/webdriver-sampler-your-top-ten-questions-answered




Suggested Topics

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