1

I have an Acknowledge button and I want to click it. I have tried all the three methods listed below. But it is not working.

driver.findElement(By.cssSelector("input.btn.btn.primary")).submit();
driver.findElement(By.xpath("//*[@id='content']/div[2]/div/input")).click();
driver.findElement(By.xpath("//*[@value='I Acknowledge' ")).click();

This is the HTML Of the page:

<input class="btn btn-primary" type="button" value="I Acknowledge">
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
JOE_D
  • 21
  • 5

2 Answers2

0

Try with this css locator:

input[class='btn btn-primary'][value='I Acknowledge']

  • I tried it but still its not working driver.findElement(By.cssSelector("input[class='btn btn-primary'][value='I Acknowledge']")).submit(); both with click or either submit its not working ... – JOE_D Jan 23 '20 at 17:44
  • Try javascript executor ((JavascriptExecutor) driver).executeScript("arguments[0].click();", element); – Yalcin Batur Jan 23 '20 at 21:27
  • i tried javascript executor both with css selector and xpath but still its not working WebElement element= new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='btn btn-sm btn-primary' and text()='No'']"))); // WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.btn.btn-sm.btn-primary[data-ng-click*='attemptNext']"))); JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("arguments[0].click();", element); – JOE_D Jan 29 '20 at 13:12
0

To click on the I Acknowledge element you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.btn.btn-primary[value='I Acknowledge']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='btn btn-primary' and @value='I Acknowledge']"))).click();
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • 1
    Thank you the above code worked, I appreciate it. I was struggling with it for a while – JOE_D Jan 24 '20 at 15:27
  • @JOE_D [Upvote](https://stackoverflow.com/help/why-vote) the answer if this/any answer is/was helpful to you for the benefit of the future readers. – DebanjanB Jan 28 '20 at 21:25