user2526197
user2526197

Reputation: 1

Checking for an image in a loop with Sikuli

I have a script in Sikuli that is a bot. It looks like this:

for i in range (100):
    find(YoutubeChannelButton)
    click(YoutubeChannelButton)
    wait(3)
    while(1): 
        if exists(LikeButton):
            click(LikeButton)
            wait(6)
            click(Close)
            wait(10)
        else:
            click(Close)
            wait(5)

I want it to click the "like" button if it exists and when it doesn't exist I want it to click on the close button and then retry the process all over again.

So in summary:

The problem is that it does the job one time (correctly) and then it starts closing all the pages.

Upvotes: 0

Views: 7443

Answers (1)

Nathaniel Waisbrot
Nathaniel Waisbrot

Reputation: 24493

We'd have to see some screenshots of what you're working with to be sure, but it looks to me like you've set up your loop wrong. If the LikeButton doesn't exist, it clicks close and restarts the loop. Unless the window behind the current one has a LikeButton, it still won't exist, so we'll close that window too, and so on.

Why don't you write it as

for i in range (100):
    find(YoutubeChannelButton)
    click(YoutubeChannelButton)
    wait(3)
    if exists(LikeButton):
        click(LikeButton)
        wait(6)
        click(Close)
        wait(10)
    else:
        click(Close)
        wait(5)

Upvotes: 1

Related Questions