How do I get an attribute value for a web element. For instance, if I wanted to check the state of a checkbox I want to be able to check a specific attribute. The get value operation only seems to work on the value attribute.
Hi, to target an attribute of an element with an xpath you can append /@attribute-name
to the element’s xpath.
For instance if you wanted to get the value of the ‘aria-checked’ attribute of the checkbox with xpath //div[text()="Lettuce"]
from Checkbox Example (Two State) | WAI-ARIA Authoring Practices 1.1 you could use the xpath //div[text()="Lettuce"]/@aria-checked
You can copy / paste the following example into Orqa to try it out:
web.start ( url = 'https://www.w3.org/TR/wai-aria-practices-1.1/examples/checkbox/checkbox-1/checkbox-1.html' )
checked = web.getvalue ( target = '//div[text()="Lettuce"]/@aria-checked' )
Hi,
This works great for an attribute. Is it also possible to get a property for a web element, e.g. clientHeight, checked etc
For a javascript property rather than an attribute, you can first get a handle to the web element using the ‘Get an Element from Browser’ operation, then use the ‘Run JavaScript in Browser’ operation using the element as an argument.
The javascript operation takes a list of arguments to pass to the browser, which becomes available to use in the javascript using the variable name ‘arguments’
Modifying the previous to instead get the clientHeight of the object, you could do the following:
web.start ( url = 'https://www.w3.org/TR/wai-aria-practices-1.1/examples/checkbox/checkbox-1/checkbox-1.html' )
lettuceCheckbox = web.getelement ( target = '//div[text()="Lettuce"]' )
lettuceCheckboxHeight = web.runjs ( javaScript = 'return arguments[0].clientHeight' , arguments = ^[lettuceCheckbox]^ )
Perfect, worked a treat.
Thanks