Using global variable as an attribute

Hello all,
In my app an attribute (aria-label) is used a lot of time, it’s value is unique most of the time and I want to use it as a global variable, is it possible? I read posts about attribute value parameterization but I need to use the global variable as attribute, not value. I don’t have id’s or other specific attributes unfortunately

1 Like

I’m not sure it is a good way to go, however, it does seem to be doable. You have to know how to structure the Global Variable, such as including the at sign (@ ) if you are using xpath, and placement of appropriate double quotes and single quotes, and replacing the appropriate structure in the element’s pathway within the Object Repository. I did it only for two items. My little test is below:

GlobalVariable.gAttribute = '@name'
myItem = com.Tools.makeTO("//input[${GlobalVariable.gAttribute}='AllOpenPostedField']")
WebUI.verifyElementVisible(myItem)
WebUI.verifyElementVisible(findTestObject('myPage/MainPage/input_Standard view_Show filter'))

GlobalVariable.gAttribute = '@id'
myItem = com.Tools.makeTO("//span[contains(${GlobalVariable.gAttribute},'table_custpaym_') and contains(${GlobalVariable.gAttribute}, '_ShowUserCreatedOnly_check')]")
WebUI.verifyElementVisible(myItem)
WebUI.verifyElementVisible(findTestObject('myPage/MainPage/input_Standard view_Show user-created only'))

image

Edit: I created the objects in code so you could see it, but you could do it in your Object Repository.
Edit2: You also have to know if you are using xpath or css, as you would have to structure the whole in a different way.

1 Like