On Sunday, December 29, 2013 11:36:23 PM UTC-8, Colin Milyoni wrote:
>
> Hi folks,
>
> I'm new to both ruby and to watir, so I apologize in advance if this is a
> massive rookie mistake. Assistance of any level is greatly appreciated.
>
> My problem is that I am running into a gigantic delay when executing a
> simple watir script. This is the first time that I've run into such a large
> delay.
>
> The point of the script is to go into Facebook's Developers section, open
> an app, then individually remove test users from the app by clicking on a
> checkbox which corresponds to a table row, then clicking a button on the
> page which initiates a delete action, confirming the delete, then closing
> the window. As you can see, I have a while-loop which will end the script
> once the table has been thinned to only 11.
>
> Here is the code itself:
>
> require 'watir-webdriver'
> b = Watir::Browser.new :chrome
>
>
> b.goto "http://www.facebook.com"
> b.text_field(:name=> "email").set "xxxxxxxxxxxxxxxxx"
> b.text_field(:name=> "pass").set "xxxxxxxxxx"
> b.input(:value=>"Log In").click
>
> b.goto "
> https://developers.facebook.com/apps/1423456271203959/roles?role=test+users
> "
>
> rows = b.elements(:class=>"odd").size
>
> while rows > 10
> b.tr<http://www.google.com/url?q=http%3A%2F%2Fb.tr&sa=D&sntz=1&usg=AFQjCNFWCbRTc71PLfqHI3ZwVihaj0l42A>
> (:id =>/test_user/, :index => 10).checkbox(:type =>"checkbox").set
> b.input(:type =>"submit", :value=>"Remove").click
> sleep 1
> b.input(:type =>"button", :value=>"Remove").click
> sleep 1
>
> sleep 2
> b.input(:type =>"button", :value=>"Close").click
> end
>
> puts "Purge completed!"
>
>
> After running the code line-by-line in IRB, I am able to conclusively
> isolate the issue to this line of code:
>
> b.tr(:id =>/test_user/, :index => 10).checkbox(:type =>"checkbox").set
>
> You can see how long it takes this line to execute by viewing the attached
> swf file called "Remove problem_with_selecting_ID_12-29-13.swf"
>
> When this line of code runs, the script takes 30-60 seconds just to run
> that single line of code. Apparently that method is a little too complex,
> but I'm not sure exactly why that is. Would anyone be able to explain to
> me what the problem is exactly? My hunch is that the way that it is
> parsing the DOM for that method is very inefficient. I'm sure there is
> another way I could write my code but I would most be interesting in being
> pointed to a resource which explains why it is that this is so inefficient.
> I'd really appreciate that.
>
> Thanks,
>
> Colin
>
I don't know the technical reason, but it does seem that once you get
inside a table, things can be very slow.
as an alternative (although the suggestion to use the FB API is superior)
you could try building a collection of rows, check that the size is above
11, and if so have it iterate over the first size-11 elements in the row
collection setting the checkbox
user_rows = b.trs(:class => 'odd')
if rows.size > 10
10..rows.size-1 do |i|
rows[i].checkbox(:type =>"checkbox").set
end
b.input(:type =>"submit", :value=>"Remove").click
sleep 1
b.input(:type =>"button", :value=>"Remove").click
sleep3
b.input(:type =>"button", :value=>"Close").click
end
or something along those lines (I'm making some assumptions about their UI
that you can check multiple boxen and then purge all at once
--
--
Before posting, please read http://watir.com/support. In short: search before
you ask, be nice.
[email protected]
http://groups.google.com/group/watir-general
[email protected]
---
You received this message because you are subscribed to the Google Groups
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.