Why is getAttribute returning null in this scenario?

I’m trying to use the getAttribute method to get an attribute of an object however the value coming back is null. The data-tileversion attribute is a custom attribute for our application and contains a version number. I’m able to work around this by using the value attribute and using substring to extract the version number from the string as it contains a tile code and the tile version. The data-tileversion attribute only contains the version number and would be more robust than relying on substring in the event the substring index changes. How can I get the value of the data-tileversion attribute?

Example:

What my question is in reference to:
HTML of Select Option:
image

getAttribute returns null
actualVersion = WebUI.getAttribute(findTestObject('Object Repository/Web/Management Portal/HomeScreen/Switcher/select_--Select an unauthenticated Home Screen Tile'), 'data-tileversion')

Workaround works and returns the value attribute of the option currently set :
actualVersion = WebUI.getAttribute(findTestObject('Object Repository/Web/Management Portal/HomeScreen/Switcher/select_--Select an unauthenticated Home Screen Tile'), 'value')

However the string contains some extra I don’t care about and the code above returns:

342333A4-B8F7-49AF-AC44-D89CBCD7DD0F~3.3.0

I’m then using substring to return only the version number from the string to compare against the expected version number:

WebUI.verifyNotMatch(actualVersion.substring(37), hsVersion, false)

returns: 3.3.0

1 Like

It could be that your pathway is to your <select> object,
select_--Select an unauthenticated Home Screen Tile
and not to one of the drop-down <option> attributes and therefore is getting the return of attribute there.
I think you will have to play with the Selenium “select” statement to delve more into your attribute snag. Or, get all the <option>s into a List<WebElement> and then parse the one you want and get its attribute there.

1 Like