katalon-studiokatalon-recorder

Click Each Button In Container


I would like to use Katalon to click each button within a container.

The webpages are set up roughly like the following where the class structure for each button is the same, the text could vary, and their URLs are distinct.

<div class="container">
    <div class="button">
        <a href="page1.html" class="description" role="button">
            Page 1
        </a>
    </div>
    <div class="button">
        <a href="page2.html" class="description" role="button">
            Page 2
        </a>
    </div>
    <div class="button">
        <a href="page3.html" class="description" role="button">
            Page 3
        </a>
    </div>
</div>

I want to be able to click each of the buttons to visit their links by clicking one, returning to the previous page, and clicking the next.

I would also like it to be extensible since there may not always be the same number of button on the page.

In Katalon Studio, I have the following script which counts the number of buttons on the page.

WebUI.openBrowser('')
WebUI.navigateToUrl('http://button-container.com')
def buttonObject = findTestObject('Object Repository/Page_Buttons - div_button')
def buttonElements = WebUI.findWebElements(buttonObject, 5)
def numberOfButtons = buttonElements.size()

I wanted to then loop through and click each of the buttonElements but it looks like Katalon does not allow clicking Remote Web Elements. I was hoping I could get away with using just the single Test Object since they are mostly the same.

What is the best way to click each of the buttons within the container? Is it even possible?


Solution

  • I am giving up on using Katalon. Katalon is not really built for what I am trying to accomplish.

    For anyone wondering, I am having success using Python and Selenium to manipulate the XPATH string to iterate through the elements.

    This looks like

    for i in range(1, number_of_buttons + 1):
        button_xpath = '/html/body/div[1]/div[{}]/a'.format(i)
        button = driver.find_element_by_xpath(button_xpath)
        action.move_to_element(button)
        button.click()