0

I'm writing an automation script for a Pega Web application. I have button click functionality, but actually the button is not getting clicked when i ran the script.When I check the logs, it shows that action was performed but it's not actually clicking the button.

I tried below actions but nothing works,

WebDriverWait wait = new WebDriverWait(driver, 80);
            wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(text(),'Submit')]")));

driver.findElement(By.xpath("//button[contains(text(),'Submit')]")).click();

Then i tried below code,

WebDriverWait wait = new WebDriverWait(driver, 80);
            wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(text(),'Submit')]")));

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

button.sendKeys(Keys.RETURN);

Also i tried javascript as well,

JavascriptExecutor jse = (JavascriptExecutor) driver;
    jse.executeScript("arguments[0].click();", button);
cindy87
  • 47
  • 10

1 Answers1

0

I have faced similar issue multiple times, I fix it using -

while(driver.findElements(By.xpath("//button[contains(text(),'Submit')]")).size()!=0)
{
    driver.findElement(By.xpath("//button[contains(text(),'Submit')]")).click();
}

This is just a temporary fix, I found it somewhere on Internet only. I believe it's some issue with the driver itself.

---- Edit ----

Before clicking on the button, can you make sure if the page is completely loaded(Ajax) by using below javascript commands-

jQuery.active ==0 && document.readyState == "complete"
ayu
  • 11
  • 3