krishan krishan - 4 days ago 5
Java Question

button location error using xpath urgent?

I have to test a dynamic app using i have a button like that

<button class="btn btn-primary btn-mini" ng-click="addAnswer(question)" ng-show="question.editing">Add Answer</button>


i was trying to locate button with that but i failed

getDriver().findElement(By.xpath("//img [@ng-click='addAnswer(question)']")).click();


using css


List AddAnswerBtn =
getDriver().findElements(By.className("btn-primary"));
AddAnswerBtn.get(0).click();


give me correct line to locate it.. i dont wants to locate it using class and i wants to use xpath to locate button location

Answer

Your example shows it is a button, but your XPath is looking for an image:

//img[@ng-click='addAnswer(question)']

The above is what you are using, with img as the element type.

Change this to button.

Comments