1

HTML Code:

<button onclick="root.handleOnClick( document, this );" id="Edit_edit::0" 
title="Edit" name="Edit_edit::0" class="navbar-btn btn btn-default btn-sm cs-btn" 
type="button">Edit</button>

XPath which I used:

driver.findElement(By.xpath("//button[@title='Edit']")).click();

Please help me to run this code.

3
  • use javascriptexecutor to click the button
    – Vel Guru
    Commented Oct 17, 2018 at 6:23
  • You say you have the frames. Tell us what is the frame structure that holds your button? Is there just a frame that holds your button or frame that contains another frame that holds your button? Also show us frame html elements.
    – Alexey R.
    Commented Oct 17, 2018 at 9:25
  • Your question is not clear and lacks essential details necessary to provide an good answer sqa.stackexchange.com/help/how-to-ask Commented Oct 17, 2018 at 14:41

2 Answers 2

1

Try the below code to click button.

WebElement element=driver.findElement(By.xpath("//button[@title='Edit']"));
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);
1
  • Thanks for your code.I tried it,but its not working.There is frames,forms in my working site.Whether we have to first write code for frames,forms. Commented Oct 17, 2018 at 9:15
1

If there is a frame in the page you need to switch into the frame first and then you can access the button by using your xpath.

To switch into the frame use below command

driver.switchTo().Frame(id or class); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.