I´m trying to record a test case where a couple of radio buttons need to be checked. When using the Record on web functionality it uses:
WebUI.click(findTestObject(‘test page/label_Nej’)) However there are several radio buttons that has the same label. How do I change it to use the ID of the radio button instead? Or how do I solve it the best way?
Hi Jakob, thank you for your report.
I have tried with similar situation in following page CURA Healthcare Service. At the final step, only the last element is saved at the repository. Katalon Studio will improve the case.
For your case, I would suggest that (as I am doing) is recording as usual and save them into the Object Repository. The next step is open the Element property in Object Repository, looking for the ID property and select the checkbox next to it. Then copy and paste the element repository at the same place, rename and update the ID property correctly.
Finally, you can have different Element for these Ratio buttons.
It’s tricky for beginners whom are starting to work with Katalon package and trying to record and play with demuaut web page…
Would be lovely if demoaut page will get some improvement to avoid stuck at entry level and first contact with semi automation by Katalon.
And most important - thanks for showing that quite easily
Hi Trong,
I’ve got a similar issue, there are several questions on my webpage where I’m trying to select a Yes/No radio button for each question…
I’ve recorded as per your suggestion but it doesn’t appear to show any ID properties for the element in the object repository. The only properties that appear to be captured by the object repository are the “tag”, “class”, “text” and “xpath” properties. All of the xpaths
for all of the questions seem to be captured with the same value so it always only selects the radio button for the first question and misses out on selecting radio buttons for the remaining 6 questions.
Does anyone have any ideas how to resolve this?
Hi, recently I faced out the same problem, since Katalon seems doesn’t
capture the component in a correct way… the best solution I found out:
For a radiobuton with a ‘Consult’ label: Xpath:
//label[contains(text(),‘Consult’)]
In the same way, for a given button with a ‘Ok’ label: Xpath:
//span[contains(.,‘Ok’)]
This
is a useful way to catch out components by the text label, so you don’t
depends strictly on the structure that the component is inserted in and
of eventual modifications on this structuration. Considering that the
label used is usually unique, because of you should not assign the same
label for different interaction components (what would lead users to
mistakens); and because of radiobuttons and checkboxes usually can be
selected clicking up on labels.
References:
(1) https://www.katalon.com/resources-center/tutorials/detect-elements-xpath/
(2) https://www.katalon.com/resources-center/tutorials/generate-css-xpath-selector-spy-web-utility/
I´m trying to record a test case where a couple of radio buttons with the same label need to be checked.
The Code is:
‘Click Button myself’
WebUI.click(findTestObject(‘Testcase/span_myself’))
WebUI.setText(findTestObject(‘Testcase/input_birthday’), ‘01.01.1970’)
WebUI.click(findTestObject(‘Testcase/label_female’))
'Click Button husband ’
WebUI.click(findTestObject('Testcase/span_husband))
WebUI.setText(findTestObject(‘Testcase/input_birthday’), ‘01.01.1980’)
WebUI.click(findTestObject(‘Testcase/label_female’))
'Click Button child ’
WebUI.click(findTestObject('Testcase/span_child))
WebUI.setText(findTestObject(‘Testcase/input_birthday’), ‘01.01.2008’)
WebUI.click(findTestObject(‘Testcase/label_female’))
Chrome shows the ID (“id=Name-VN”). Its always the same object ID.
If I play the code, only the first radio button is set to “female”, the rest remain empty.
I have tried the solution of Trong_bui, unfortunately without success. Is there a solution for this?
You will need to either:
1.) Write a custom locator for the radio buttons that includes and index parameter (recommended).
or
2.) Create a new Test Object for each ‘duplicate’ radio button.
I think the problem you are having is here:
Each of the items in bold above are referencing the same element (the first ‘female’ radio button). So basically you are clicking that same radio button three times.
Hi Brandon_Hein,
many thanks for your answer. I have implemented solution 1.
Here are the details:
- copy and dubplicate the Objekct “female” as “female2” in the Object Repository
- open the Settings of “female2” and click “Attributes”
- add “ID equals name-wife-husband” - you can get the ID from Chrome: Just show with the Mouse pointer to the Radio Button of the page, click right Mouse button and choose “investigate” or “analyze” (I am not sure, i use the german Browser)
Search the ID of the Radio Button in the Source Code (here: “name-wife-husband”). - Mark “tag equals label”, “for equals name-wife-husband” and “text equals wife”
It runs!