0

In my script below code when Thread.sleep() is not used, then it throws an exception "element click intercepted: Element <button _ngcontent-yyo-c131="" class="btn btn-sm btn-light border ml-3">...</button> 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')}

1 Answer 1

0

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 DOM in case of failure, this way you will get the full picture regarding what went wrong, i.e. put your code into a try block 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: The WebDriver Sampler: Your Top 10 Questions Answered

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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