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?
driver.findElement(By.css("input[value='Cancel']")).click()
document.getElement()
. It isdocument.getElementById()
. For finding element by xpath using javascriptexecutor you have to useWebElement element=(WebElement)jse.executeScript("document.evaluate('xpath here')")
. Check the syntax of evaluate. It also takes some more arguments.