I have some buttons with an onclick attribute and some that don’t. I want to check if the specified element has the onclick attribute. How can I do this?
getAttribute() returns the attribute value when it has one. When it doesn’t, it throws a RuntimeException and stops the test (even when I wrap it in a try/catch block).
$onclickValue = $this->getAttribute("$locator@onclick"); //works when the attribute exists
By using
getEval(), you can execute the javascripthasAttribute()function. UsingfindElement(), will allow you to work with any type of locator pattern.Note that
getEval()returns a string, not a boolean.