Jump to content
UBot Underground

My loop is stuck on 13 iterations


Recommended Posts

Hello Everyone, 

 

Thanks for taking the time to review my issue. I'm still pretty new to building bots, so I'm sure there's something I'm doing wrong in my code:

ui open file("Load Settings File", #open_settings)
ui save file("Create new settings file", #settings)
ui open file("Open content csv file", #content_csv_file)
if($comparison(#open_settings, "!=", "")) {
    then {
        create table from file(#open_settings, &store_credentials)
        set(#domain, $table cell(&store_credentials, 0, 1), "Global")
        set(#username, $table cell(&store_credentials, 0, 2), "Global")
        set(#password, $table cell(&store_credentials, 0, 3), "Global")
        set(#vid_cat_select, $table cell(&store_credentials, 0, 4), "Global")
        set(#tags, $table cell(&store_credentials, 0, 5), "Global")
    }
    else {
    }
}
if($comparison(#settings, "!=", "")) {
    then {
        add item to list(%settings_location, #settings, "Delete", "Global")
        add item to list(%settings_domain, #domain, "Delete", "Global")
        add item to list(%settings_user, #username, "Delete", "Global")
        add item to list(%settings_pass, #password, "Delete", "Global")
        add item to list(%settings_category, #vid_cat_select, "Delete", "Global")
        add item to list(%settings_tags, #tags, "Delete", "Global")
        add list to table as column(&store_credentials, 0, 0, %settings_location)
        add list to table as column(&store_credentials, 0, 1, %settings_domain)
        add list to table as column(&store_credentials, 0, 2, %settings_user)
        add list to table as column(&store_credentials, 0, 3, %settings_pass)
        add list to table as column(&store_credentials, 0, 4, %settings_category)
        add list to table as column(&store_credentials, 0, 5, %settings_tags)
        save to file(#settings, &store_credentials)
        set(#domain, $table cell(&store_credentials, 0, 1), "Global")
        set(#username, $table cell(&store_credentials, 0, 2), "Global")
        set(#password, $table cell(&store_credentials, 0, 3), "Global")
        set(#vid_cat_select, $table cell(&store_credentials, 0, 4), "Global")
        set(#tags, $table cell(&store_credentials, 0, 5), "Global")
    }
    else {
    }
}
ui text box("WordPress Domain", #domain)
ui text box("Username:", #username)
ui text box("Password:", #password)
set(#position, 0, "Global")
ui text box("Category to post in:", #vid_cat_select)
ui block text("Add Tags", #tags)
ui stat monitor("Media available in file:", $table total rows(&song_and_title))
ui stat monitor("Media published so far:", #position)
clear table(&song_and_title)
create table from file(#content_csv_file, &song_and_title)
navigate("http://{#domain}/wp-admin/", "Wait")
wait for browser event("Everything Loaded", "")
if($exists(<title="Password Lost and Found">)) {
    then {
        type text(<id="user_login">, #username, "Standard")
        wait(1)
        type text(<id="user_pass">, #password, "Standard")
        wait(1)
        click(<name="wp-submit">, "Left Click", "No")
        wait for browser event("Everything Loaded", "")
    }
    else {
    }
}
wait(2)
loop while($comparison(#position, "!=", $table total rows(&song_and_title))) {
    click(<(title="Add New" AND class="ab-item")>, "Left Click", "No")
    wait for browser event("Everything Loaded", "")
    wait(2)
    click(<href="post-new.php">, "Left Click", "No")
    wait for browser event("Everything Loaded", "")
    wait(2)
    click(<href="#screen-options-wrap">, "Left Click", "No")
    wait(2)
    change attribute(<id="post-song-data-hide">, "checked", "true")
    change attribute(<id="post-video-data-hide">, "checked", "false")
    wait(2)
    click(<id="show-settings-link">, "Left Click", "No")
    wait(1)
    type text(<id="title">, $table cell(&song_and_title, #position, 0), "Standard")
    wait(3)
    click(<(tagname="a" AND id="post-optionst")>, "Left Click", "No")
    wait(2)
    click(<id="are-you-submitting-from-soundcloud_false">, "Left Click", "No")
    wait(2)
    change attribute($element offset(<url field>, 1), "value", $table cell(&song_and_title, #position, 1))
    wait(2)
    click(<(tagname="a" AND innertext="Add Entry")>, "Left Click", "No")
    wait(3)
    click(<id="category-add-toggle">, "Left Click", "No")
    wait(2)
    type text(<id="newcategory">, #vid_cat_select, "Standard")
    wait(2)
    click(<id="category-add-submit">, "Left Click", "No")
    wait for browser event("Everything Loaded", "")
    wait(2)
    type text(<(tagname="input" AND class="newtag form-input-tip")>, #tags, "Standard")
    wait for browser event("Everything Loaded", "")
    wait(2)
    click(<id="publish">, "Left Click", "No")
    increment(#position)
}

No matter what I do when the bot reach 13 iterations everything stops, but the run button remains grey (as if the bot is still running). I have tried while loop, normal loop with table length, etc. I have compiled various bots also. Everything always works 100% as expected until 13 is reached.

 

Attached you can see the csv file containing the title & song url.

 

Thanks for your suggestions.

ready-to-post_2.csv

Edited by askwpcoach
Link to post
Share on other sites
I just took a very quick look. Without testing it. 

 

But I would add wait at the end of your loop. 

Because at the moment it will do:

click(<id="publish">, "Left Click", "No")

then jump to the top of the loop and do:

click(<(title="Add New" AND class="ab-item")>, "Left Click", "No")

 

And depending on what the site is doing, that might be to fast.

 

I also highly recommend using 

wait for element 

 

This is much more reliable than wait for browser event. 

I would always use wait for element and wait for the exact element I want to click or scrape with my next command.

 

Hope that helps a bit.

 

Cheers

Dan

Link to post
Share on other sites

Hello Dan,

 

Thanks for the suggestion, I added the wait for element at the end of the loop (before the iteration). But I still have the same result, the bot is fully functional and working perfectly until the 13th iteration.

ui open file("Load Settings File", #open_settings)
ui save file("Create new settings file", #settings)
ui open file("Open content csv file", #content_csv_file)
if($comparison(#open_settings, "!=", "")) {
    then {
        create table from file(#open_settings, &store_credentials)
        set(#domain, $table cell(&store_credentials, 0, 1), "Global")
        set(#username, $table cell(&store_credentials, 0, 2), "Global")
        set(#password, $table cell(&store_credentials, 0, 3), "Global")
        set(#vid_cat_select, $table cell(&store_credentials, 0, 4), "Global")
        set(#tags, $table cell(&store_credentials, 0, 5), "Global")
    }
    else {
    }
}
if($comparison(#settings, "!=", "")) {
    then {
        add item to list(%settings_location, #settings, "Delete", "Global")
        add item to list(%settings_domain, #domain, "Delete", "Global")
        add item to list(%settings_user, #username, "Delete", "Global")
        add item to list(%settings_pass, #password, "Delete", "Global")
        add item to list(%settings_category, #vid_cat_select, "Delete", "Global")
        add item to list(%settings_tags, #tags, "Delete", "Global")
        add list to table as column(&store_credentials, 0, 0, %settings_location)
        add list to table as column(&store_credentials, 0, 1, %settings_domain)
        add list to table as column(&store_credentials, 0, 2, %settings_user)
        add list to table as column(&store_credentials, 0, 3, %settings_pass)
        add list to table as column(&store_credentials, 0, 4, %settings_category)
        add list to table as column(&store_credentials, 0, 5, %settings_tags)
        save to file(#settings, &store_credentials)
        set(#domain, $table cell(&store_credentials, 0, 1), "Global")
        set(#username, $table cell(&store_credentials, 0, 2), "Global")
        set(#password, $table cell(&store_credentials, 0, 3), "Global")
        set(#vid_cat_select, $table cell(&store_credentials, 0, 4), "Global")
        set(#tags, $table cell(&store_credentials, 0, 5), "Global")
    }
    else {
    }
}
ui text box("WordPress Domain", #domain)
ui text box("Username:", #username)
ui text box("Password:", #password)
set(#position, 0, "Global")
ui text box("Category to post in:", #vid_cat_select)
ui block text("Add Tags", #tags)
ui stat monitor("Media available in file:", $table total rows(&song_and_title))
ui stat monitor("Media published so far:", #position)
clear table(&song_and_title)
create table from file(#content_csv_file, &song_and_title)
navigate("http://{#domain}/wp-admin/", "Wait")
wait for browser event("Everything Loaded", "")
if($exists(<title="Password Lost and Found">)) {
    then {
        type text(<id="user_login">, #username, "Standard")
        wait(1)
        type text(<id="user_pass">, #password, "Standard")
        wait(1)
        click(<name="wp-submit">, "Left Click", "No")
        wait for browser event("Everything Loaded", "")
    }
    else {
    }
}
wait(2)
loop while($comparison(#position, "!=", $table total rows(&song_and_title))) {
    navigate("http://{#domain}/wp-admin/post-new.php", "Wait")
    wait for element(<innertext="Add New Post">, "", "Appear")
    click(<href="#screen-options-wrap">, "Left Click", "No")
    wait(2)
    change attribute(<id="post-song-data-hide">, "checked", "true")
    change attribute(<id="post-video-data-hide">, "checked", "false")
    wait(2)
    click(<id="show-settings-link">, "Left Click", "No")
    wait(1)
    type text(<id="title">, $table cell(&song_and_title, #position, 0), "Standard")
    wait(3)
    click(<(tagname="a" AND id="post-optionst")>, "Left Click", "No")
    wait(2)
    click(<id="are-you-submitting-from-soundcloud_false">, "Left Click", "No")
    wait(2)
    change attribute($element offset(<url field>, 1), "value", $table cell(&song_and_title, #position, 1))
    wait(2)
    click(<(tagname="a" AND innertext="Add Entry")>, "Left Click", "No")
    wait(3)
    click(<id="category-add-toggle">, "Left Click", "No")
    wait(2)
    type text(<id="newcategory">, #vid_cat_select, "Standard")
    wait(2)
    click(<id="category-add-submit">, "Left Click", "No")
    wait for browser event("Everything Loaded", "")
    wait(2)
    type text(<(tagname="input" AND class="newtag form-input-tip")>, #tags, "Standard")
    wait for browser event("Everything Loaded", "")
    wait(2)
    click(<id="publish">, "Left Click", "No")
    wait for element(<innertext="Post published. View post">, "", "Appear")
    increment(#position)
}

Link to post
Share on other sites

Your script looks good except where you use everything loaded, all of them

 

use wait for element as Dan said

 

like the category change

 

I'll bet that it's not being recognized and skipping that step then stops your script

 

you can wait for something to disappear as well and set the time out to something reasonable otherwise it waits like 2 mins is default I think.

 

it's in the advanced part of the node

 

 

HTHelps,

 

CD

Link to post
Share on other sites

Thanks for your suggestions, the wait for browser event wasn't important so I removed them from the loop. The category change and tags change are very small ajax buttons that submits text (screenshot: http://screencast.com/t/h8uJ9wW9KrY ). The wait for browser event commands are removed but the bot still stops at 13. Will it be helpful if I provide WordPress credentials to you so you can run it from your computer? I will send in private.

ui open file("Load Settings File", #open_settings)
ui save file("Create new settings file", #settings)
ui open file("Open content csv file", #content_csv_file)
if($comparison(#open_settings, "!=", "")) {
    then {
        create table from file(#open_settings, &store_credentials)
        set(#domain, $table cell(&store_credentials, 0, 1), "Global")
        set(#username, $table cell(&store_credentials, 0, 2), "Global")
        set(#password, $table cell(&store_credentials, 0, 3), "Global")
        set(#vid_cat_select, $table cell(&store_credentials, 0, 4), "Global")
        set(#tags, $table cell(&store_credentials, 0, 5), "Global")
    }
    else {
    }
}
if($comparison(#settings, "!=", "")) {
    then {
        add item to list(%settings_location, #settings, "Delete", "Global")
        add item to list(%settings_domain, #domain, "Delete", "Global")
        add item to list(%settings_user, #username, "Delete", "Global")
        add item to list(%settings_pass, #password, "Delete", "Global")
        add item to list(%settings_category, #vid_cat_select, "Delete", "Global")
        add item to list(%settings_tags, #tags, "Delete", "Global")
        add list to table as column(&store_credentials, 0, 0, %settings_location)
        add list to table as column(&store_credentials, 0, 1, %settings_domain)
        add list to table as column(&store_credentials, 0, 2, %settings_user)
        add list to table as column(&store_credentials, 0, 3, %settings_pass)
        add list to table as column(&store_credentials, 0, 4, %settings_category)
        add list to table as column(&store_credentials, 0, 5, %settings_tags)
        save to file(#settings, &store_credentials)
        set(#domain, $table cell(&store_credentials, 0, 1), "Global")
        set(#username, $table cell(&store_credentials, 0, 2), "Global")
        set(#password, $table cell(&store_credentials, 0, 3), "Global")
        set(#vid_cat_select, $table cell(&store_credentials, 0, 4), "Global")
        set(#tags, $table cell(&store_credentials, 0, 5), "Global")
    }
    else {
    }
}
ui text box("WordPress Domain", #domain)
ui text box("Username:", #username)
ui text box("Password:", #password)
set(#position, 0, "Global")
ui text box("Category to post in:", #vid_cat_select)
ui block text("Add Tags", #tags)
ui stat monitor("Media available in file:", $table total rows(&song_and_title))
ui stat monitor("Media published so far:", #position)
clear table(&song_and_title)
create table from file(#content_csv_file, &song_and_title)
navigate("http://{#domain}/wp-admin/", "Wait")
wait for browser event("Everything Loaded", "")
if($exists(<title="Password Lost and Found">)) {
    then {
        type text(<id="user_login">, #username, "Standard")
        wait(1)
        type text(<id="user_pass">, #password, "Standard")
        wait(1)
        click(<name="wp-submit">, "Left Click", "No")
        wait for browser event("Everything Loaded", "")
    }
    else {
    }
}
wait(2)
loop while($comparison(#position, "!=", $table total rows(&song_and_title))) {
    navigate("http://{#domain}/wp-admin/post-new.php", "Wait")
    wait for element(<innertext="Add New Post">, "", "Appear")
    click(<href="#screen-options-wrap">, "Left Click", "No")
    wait(2)
    change attribute(<id="post-song-data-hide">, "checked", "true")
    change attribute(<id="post-video-data-hide">, "checked", "false")
    wait(2)
    click(<id="show-settings-link">, "Left Click", "No")
    wait(1)
    type text(<id="title">, $table cell(&song_and_title, #position, 0), "Standard")
    wait(3)
    click(<(tagname="a" AND id="post-optionst")>, "Left Click", "No")
    wait(2)
    click(<id="are-you-submitting-from-soundcloud_false">, "Left Click", "No")
    wait(2)
    change attribute($element offset(<url field>, 1), "value", $table cell(&song_and_title, #position, 1))
    wait(2)
    click(<(tagname="a" AND innertext="Add Entry")>, "Left Click", "No")
    wait(3)
    click(<id="category-add-toggle">, "Left Click", "No")
    wait(2)
    type text(<id="newcategory">, #vid_cat_select, "Standard")
    wait(2)
    click(<id="category-add-submit">, "Left Click", "No")
    wait(2)
    type text(<(tagname="input" AND class="newtag form-input-tip")>, #tags, "Standard")
    wait(2)
    click(<id="publish">, "Left Click", "No")
    wait for element(<innertext="Post published. View post">, "", "Appear")
    increment(#position)
}

Link to post
Share on other sites

:-) I know this may not mean much, but I'm a WordPress developer. I know in detail everything that is in the site and can assure you there are no security triggers. I have been creating small bots to do this type of task and only ran into trouble on this one. 

 

Nothing on the site is broken or disabled, etc... The bot just stops after posting the 13th item no matter what I do.

Link to post
Share on other sites
askwpcoach,

At the office we have a lots of code that has been running well for years.

So when we have a problem we first check the data since the code has proven to be solid for a long time.

 

A couple of suggested test runs I would make with your code:

1. Delete rows 12, 13 and 14. Run the code and see what happens and look for a clue.

2. Sort the input file into descending order. Run the code and see what happens and look for a clue.

 

Sorry that's not much help but it's worth a try.

Link to post
Share on other sites

@Arunner26 Thanks for the recommendation. I started off with 309 items to post, since then I have posted 177 during debugging and running. I have analyzed and changed things around in the data file, but still get the same results. I have run the bot on various computers also.

 

I think I will have no other choice than to finish the job 13 posts at a time :-( . This will take me much longer than I expected when building the bot, but I suppose it is still less time than it would take doing it manually.

 

Thanks again for all of your attempts to help.

Edited by askwpcoach
Link to post
Share on other sites

@Arunner26 Thanks for the recommendation. I started off with 309 items to post, since then I have posted 177 during debugging and running. I have analyzed and changed things around in the data file, but still get the same results. I have run the bot on various computers also.

 

I think I will have no other choice than to finish the job 13 posts at a time :-( . This will take me much longer than I expected when building the bot, but I suppose it is still less time than it would take doing it manually.

 

Thanks again for all of your attempts to help.

 

In that case, you may want to try and put the current loop into a loop,

In the current loop you reduce it to do 10 iterations and in the new outter loop you reset all the variables and lists used and restart the inner loop.

The outter loop continues until all the posts are done.

  • Like 1
Link to post
Share on other sites

@Arunner26 Just finished running the bot, it made it to 14 this time (see screenshot).

ui open file("Load Settings File", #open_settings)
ui save file("Create new settings file", #settings)
ui open file("Open content csv file", #content_csv_file)
if($comparison(#open_settings, "!=", "")) {
    then {
        create table from file(#open_settings, &store_credentials)
        set(#domain, $table cell(&store_credentials, 0, 1), "Global")
        set(#username, $table cell(&store_credentials, 0, 2), "Global")
        set(#password, $table cell(&store_credentials, 0, 3), "Global")
        set(#vid_cat_select, $table cell(&store_credentials, 0, 4), "Global")
        set(#tags, $table cell(&store_credentials, 0, 5), "Global")
    }
    else {
    }
}
if($comparison(#settings, "!=", "")) {
    then {
        add item to list(%settings_location, #settings, "Delete", "Global")
        add item to list(%settings_domain, #domain, "Delete", "Global")
        add item to list(%settings_user, #username, "Delete", "Global")
        add item to list(%settings_pass, #password, "Delete", "Global")
        add item to list(%settings_category, #vid_cat_select, "Delete", "Global")
        add item to list(%settings_tags, #tags, "Delete", "Global")
        add list to table as column(&store_credentials, 0, 0, %settings_location)
        add list to table as column(&store_credentials, 0, 1, %settings_domain)
        add list to table as column(&store_credentials, 0, 2, %settings_user)
        add list to table as column(&store_credentials, 0, 3, %settings_pass)
        add list to table as column(&store_credentials, 0, 4, %settings_category)
        add list to table as column(&store_credentials, 0, 5, %settings_tags)
        save to file(#settings, &store_credentials)
        set(#domain, $table cell(&store_credentials, 0, 1), "Global")
        set(#username, $table cell(&store_credentials, 0, 2), "Global")
        set(#password, $table cell(&store_credentials, 0, 3), "Global")
        set(#vid_cat_select, $table cell(&store_credentials, 0, 4), "Global")
        set(#tags, $table cell(&store_credentials, 0, 5), "Global")
    }
    else {
    }
}
ui text box("WordPress Domain", #domain)
ui text box("Username:", #username)
ui text box("Password:", #password)
set(#position, 0, "Global")
ui text box("Category to post in:", #vid_cat_select)
ui block text("Add Tags", #tags)
ui stat monitor("Media available in file:", $table total rows(&song_and_title))
ui stat monitor("Media published so far:", #position)
clear table(&song_and_title)
create table from file(#content_csv_file, &song_and_title)
navigate("http://{#domain}/wp-admin/", "Wait")
wait for browser event("Everything Loaded", "")
if($exists(<title="Password Lost and Found">)) {
    then {
        type text(<id="user_login">, #username, "Standard")
        wait(1)
        type text(<id="user_pass">, #password, "Standard")
        wait(1)
        click(<name="wp-submit">, "Left Click", "No")
        wait for browser event("Everything Loaded", "")
    }
    else {
    }
}
wait(2)
loop while($comparison(#position, "!=", $table total rows(&song_and_title))) {
    loop(10) {
        navigate("http://{#domain}/wp-admin/post-new.php", "Wait")
        wait for element(<innertext="Add New Post">, "", "Appear")
        click(<href="#screen-options-wrap">, "Left Click", "No")
        wait(2)
        change attribute(<id="post-song-data-hide">, "checked", "true")
        change attribute(<id="post-video-data-hide">, "checked", "false")
        wait(2)
        click(<id="show-settings-link">, "Left Click", "No")
        wait(1)
        type text(<id="title">, $table cell(&song_and_title, #position, 0), "Standard")
        wait(3)
        click(<(tagname="a" AND id="post-optionst")>, "Left Click", "No")
        wait(2)
        click(<id="are-you-submitting-from-soundcloud_false">, "Left Click", "No")
        wait(2)
        change attribute($element offset(<url field>, 1), "value", $table cell(&song_and_title, #position, 1))
        wait(2)
        click(<(tagname="a" AND innertext="Add Entry")>, "Left Click", "No")
        wait(3)
        click(<id="category-add-toggle">, "Left Click", "No")
        wait(2)
        type text(<id="newcategory">, #vid_cat_select, "Standard")
        wait(2)
        click(<id="category-add-submit">, "Left Click", "No")
        wait(2)
        type text(<(tagname="input" AND class="newtag form-input-tip")>, #tags, "Standard")
        wait(2)
        click(<id="publish">, "Left Click", "No")
        wait for element(<innertext="Post published. View post">, "", "Appear")
        increment(#position)
    }
}

post-17160-0-38428700-1416592286_thumb.png

Link to post
Share on other sites

Thanks for all of your attempts to assist. This bot task is now finished, so I no longer need it to work. However I think it may be worth it to say the following:

 

  1. I have created 7 bots on this particular migration project, all of which have had tasks exceeding 300 iterations. None of my other bots have had trouble.
  2. I have run the bot on more than one computer
  3. I have made adjustments to the code

Is there any way I can debug the exe bot just for the sake of learning what I did / went wrong ?

 

Thanks.

Link to post
Share on other sites

My suggestions

 

<1> Wait for element needs a timeout value (bold 15 is wait time, its under advanced settings) wait for element(<title="My Account">, 15"Appear")

 

if you want to know exactly where it freezes or stops you can set a status each step. quick example below

 

<2> set a status after each step to see where it freezes ( don't bother with waits but all other steps)

ui stat monitor("status", #status) 




set(#status, "navigate", "Global")
navigate("http://{#domain}/wp-admin/post-new.php", "Wait")
set(#status, "wait for add post element", "Global")
wait for element(<innertext="Add New Post">, "", "Appear")
set(#status, "click screen options", "Global")
click(<href="#screen-options-wrap">, "Left Click", "No")
wait(2)
set(#status, "change song data", "Global")
change attribute(<id="post-song-data-hide">, "checked", "true")
set(#status, "change video data", "Global")
change attribute(<id="post-video-data-hide">, "checked", "false")
wait(2)
set(#status, "show settings", "Global")
click(<id="show-settings-link">, "Left Click", "No")
wait(1)
set(#status, "type song and title", "Global")
type text(<id="title">, $table cell(&song_and_title, #position, 0), "Standard")

set a variable for # of times to loop using list or table total instead of while.

set(#looptotal, $list total(%list), "Global")
loop(#looptotal) {
}

<3>instead of navigate(, "Wait") use click(<href="post-new.php">"Left Click""No")

 

 

<4>after you publish you need to have a wait as well

 

<5> use defines

 

one for login for posting

 

<6> remove posted entries from table or lists or save the place you are at after each sucessful post

  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...