Automation Obstacle

Hello all.
Could you try this problem and post the solution?

Sort the number from 1 to 9. Click on ‘Swap’, if the left number is greater than the right number inside the blue bubble. Otherwise click ‘Next’. The blue text field on the bottom left will display “KEEP SORTING” until the numbers are correctly sorted.

// Assuming ‘numbers’ is an array containing the numbers 5, 6, 9, 7, 4, 1, 3, 2, 8
numbers = {5, 6, 9, 7, 4, 1, 3, 2, 8}
n = numbers.Length

// Perform Bubble Sort
for i = 0 to n-1
for j = 0 to n-i-2
// Use UI Automation activities to get the value of current and next number
current = Get Text from current blue bubble
next = Get Text from next blue bubble

    if current > next
        // Click 'Swap' button
        Click 'Swap' button using UI Automation
    else
        // Click 'Next' button
        Click 'Next' button using UI Automation
    endif
endfor

endfor

// At this point, the numbers should be sorted

note:
The problem you’ve described seems to be a classic bubble sort algorithm implemented through a user interface where you have the options to ‘Swap’ if the current number is greater than the next, or to ‘Next’ if the current number is less than or equal to the next. The goal is to sort the numbers from 1 to 9 in ascending order.

@Dinesh5

Try like this:

Add the necessary activities to the workflow as described below:

a. Assign Activities: Create variables to store the numbers to be sorted and the index of the current iteration.

b. While Loop: Use a While loop to continue sorting until the numbers are correctly sorted.

c. If Activity: Inside the While loop, use an If activity to compare the left number with the right number inside the blue bubble. If the left number is greater than the right number, click on ‘Swap’. Otherwise, click on ‘Next’.

d. Click Activities: Use Click activities to perform the ‘Swap’ and ‘Next’ actions.

e. Element Exists Activity: Use an Element Exists activity to check if the blue text field displays “KEEP SORTING”. If it does, continue with the next iteration of the loop. If not, exit the loop.

Configure the activities and properties according to the logic described in the problem statement.

Test the workflow to ensure that it correctly sorts the numbers from 1 to 9.

Like this:

Sequence
Attach Browser
Open Browser
Do While
If
Then
Click (To perform ‘Swap’ or ‘Next’ action)
Then
If
Element Exists (To check if “KEEP SORTING” is displayed)
Do While
Sequence

Hi @Dinesh5 ,

I’m totally against spoon feeding but sharing the code which I tried as an interest in challenge. The solutions provided by other community members should be helpful to you to design this.

Obstacle73589.zip (6.6 KB)

Be aware the solution isn’t optimized one. You can do it as on your own and as preferred.

Don’t forget to mark as solution if this helps.

Thanks,
Ashok :slight_smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.