gsavva
January 10, 2023, 11:26am
1
Hello team,
I searched the forum but I could not find something to solve my issue.
I am trying to fill out a form, with a list of checkboxes that is dynamic. I mean they have the same type and class but different ID.
I need to automatically fill out every checkbox that is visible.
The class is: form-checkbox agreement
The type is: checkbox
I tried the below:
def checkboxes = WebUI.findWebElements(findTestObject("Object Repository/ma/ma_signup_form/input_agreement_2"), By.cssSelector(".form-checkbox agreement"))
checkboxes.each{ WebUI.click(it) }
def checkboxes = findTestObject("Object Repository/ma/ma_signup_form/input_agreement_1").findChild(By.className("form-checkbox agreement"))
checkboxes.each{ WebUI.click(it) }
def checkboxes = findTestObject("Object Repository/ma/ma_signup_form/input_agreement_1").findElements(by.type("checkbox"))
checkboxes.each{ WebUI.click(it) }
def checkboxes = findTestObject("Object Repository/ma/ma_signup_form/input_agreement_1")
for (def checkbox : checkboxes) {
WebUI.click(checkbox)
}
Ok, what exceptions are you facing at run time?
What does the HTML look like around these checkboxes?
gsavva
January 10, 2023, 1:53pm
3
Thanks for your reply. The html is similar to the below
<div class="form-group">
<div class="row">
<div class="checkbox">
<div class="col-xs-1 col-sm-1 col-md-1 col-lg-1 hidden">
<span>
</span>
</div>
<div class="col-xs-10 col-sm-10 col-md-10 col-lg-10 agreements_container">
<label style="">
<input class="form-checkbox agreement" type="checkbox" data-agreement_id="14" name="" id="" value="1">
TEXT
</label>
<label style="">
<input class="form-checkbox agreement" type="checkbox" data-agreement_id="16" name="" id="" value="1">
TEXT
</label>
</div>
</div>
</div>
</div>
Thank you for getting back to me so quickly!
This looks like Bootstrap, straight from a codebase.
What does the rendered HTML look like in the DOM?
UPDATE: look at your attempts here. You’re using a TestObject
to find a List<WebElement>
.
Your first attempt was on the right track, but you should read the documentation .
You don’t pass in a By
as that second argument. You pass in a timeOut
.
Also you need to make sure the first argument is a TestObject
for your checkboxes, assuming you can click the checkboxes. This is why I asked you for the rendered DOM HTML for this.
Once we have that, I can advise you on the best selection strategy for the clickable checkbox widgets.
Your question has a similar solution to the below, but on an input tag, not a div tag.
You can only use “selectOptionByLabel”, “selectOptionByValue” or “selectOptionByIndex” on a select tag. In your case, you have a div.
However, you can get the dropdown items into a list and then do your thing with the list.
Click on the arrow of the dropdown and have the list display and then right click on the list and choose “Inspect”. This should display the HTML of the list. There may be a class that is similar to each item in the dropdown.
def driver = DriverFactory.getWebDriver();
Li…
You only show the HTML to the div tags, so if there is much below them, you will have to flush this out.
How about trying:
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import org.openqa.selenium.By as By
import org.openqa.selenium.Keys as Keys
import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.WebElement as WebElement
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import com.kms.katalon.core.webui.keyword.We…
Use your class attribute, and maybe type attribute, to see if you get just the elements you want.
I also might add a verification to your checkbox being checked.
for (def checkbox : checkboxes) {
WebUI.click(checkbox)
WebUI.verifyElementChecked(checkbox, 10)
}