Button click was not performed even though element was found
-
<p>I'm trying to click below button.</p> <pre><code><button class="MuiButtonBase-root MuiButton-root jss47 jss58 MuiButton-contained jss48 jss59 MuiButton-containedPrimary MuiButton-disableElevation" tabindex="0" type="button"> <span class="MuiButton-label jss49 jss60">CONTINUE</span> </button>
I used below code to click it.
WebElement continueButton = driver.findElement(By.xpath("//span[text()='CONTINUE']")); Assert.assertTrue(continueButton.isDisplayed()); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); js.executeScript("arguments[0].click();", continueButton);
Even though no exception given button was not clicked and script is not executed completely.
Can someone give me a solution ?
-
Issue resolved after adding a button availability check and increasing wait time.
WebElement continueBtn = driver.findElement(By.xpath("//span[text()='CONTINUE']"));
if(continueBtn.isDisplayed()) { try { Thread.sleep(8000); System.out.println("Waiting time 6s"); } catch (InterruptedException e) { e.printStackTrace(); } js.executeScript("arguments[0].click();", continueBtn); }else { System.out.println("Button not found"); }