Skip to main content
3 of 3
edited body
dzieciou
  • 10.5k
  • 9
  • 48
  • 102

JavascriptExecutor is not identifying the button to click in Webdriver

I have this HTML

<div class="btnContr">    
  <input type="button" onclick="return cancel();" value="Cancel"/>

Below is the xpath identified, using this xpath, I am not able to click on the button.

Xpath=//div[@class='btnContr']/input[@onclick='return cancel();']

Code written:

JavascriptExecutor jse = (JavascriptExecutor)ff;
            jse.executeScript("document.getElement(By.xpath('//div[@class='btnContr']/input[@onclick='return cancel();']').click()");

What should my code be?

user6633
  • 1
  • 1
  • 1
  • 1