问题
I have some yes/no radio buttons and it would be much faster if I did not have to register these as 'test objects' using many clicks in the UI.
Is there a way to edit my test script to find these elements by-attribute and click them?
回答1:
You don't need to use the UI (By that I presume you mean the Object Repository).
For example, if you have the following HTML:
<form action="">
<input type="radio" value="On"> On<br>
<input type="radio" value="Off"> Off<br>
</form>
You can make a parametrized object in the script (and not using web spy/record feature):
def switch = ['on', 'off']
TestObject button = new TestObject().addProperty('css', ConditionType.EQUALS, 'input[value="'+switch+'"]')
You will need to import these:
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
来源:https://stackoverflow.com/questions/52302079/katalon-script-find-element-by-attributes-and-click-it