On 8/30/11 10:39 AM, Duke wrote:
Hi folks,
Please welcome the newest user of watir! I just heard about watir when
searching for web automation, and after reading some how-to articles,
I was quite excited with my first script running below (run fine in
ubuntu x86, havent tried in mac or windows yet):
#### CODE START ####
#!/usr/bin/env ruby
require 'rubygems'
require 'watir'
require 'nokogiri'
#require 'watir-webdriver'
#start the browser up
#browser = Watir::Browser.new :chorme
browser = Watir::Browser.start
"https://www.google.com/accounts/ServiceLogin?service=mail"
#pass in current page's html to nokogiri for parsing
page_html = Nokogiri::HTML.parse(browser.html)
text = page_html.xpath(".//*[@id='quota']").inner_text
while((text.to_f)<7621.000000)
page_html = Nokogiri::HTML.parse(browser.html)
text = page_html.xpath(".//*[@id='quota']").inner_text
puts text
sleep 2
end
#### CODE END ####
Since I am totally new to watir, I would appreciate any one helping me
with my questions below:
* Main advantage of watir compared to traditional method (manual
crawling), as far as I understand, is to reduce the number of
automated queries sent to the interested page. With what I am doing
above, am I doing it right? Is it considered as one query each time
when I call page_html.xpath(".//*[@id='quota']").inner_text? If not,
then anyone can explain to me how it is working?
* I have the feeling that the code above works as to extract infos
from HTML code, whereas the quote produced from gmail is from a
javascript. Is there a way that I capture infos from javascript
instead of HTML code?
* Now if I want to *detect* the change of quota, meaning I want a
kind of *real-time* code that reports me quota anytime when quote on
gmail changes its value. Anyone can recommend me how to achieve that?
I figured out for question 3, and part of question 2:
#!/usr/bin/env ruby
require 'rubygems'
require 'watir'
#require 'nokogiri'
#require 'watir-webdriver'
#start the browser up
browser = Watir::Browser.start
"https://www.google.com/accounts/ServiceLogin?service=mail"
curText = browser.span(:id, "quota").text
puts curText
while(1)
if(browser.span(:id, "quota").text!=curText)
curText = browser.span(:id, "quota").text
puts curText
end
end
but my feeling is that it is a little too aggressive. If somehow I can
detect the *change* of text (like using wait_until and
fire_event("onchange"), but I failed to get it to work), that would be
better. Also, somehow the text reported to me on the command line is
about 0.5 second later than the text appeared on gmail service, not sure
why.
The code now detects *javascript* element, but still crawls for text
from HTML code. I hope that there is a way of detecting javascript
variable in real time, but not sure there is one, and how to get that to
work.
Any comments/suggestions will be greatly appreciated,
Thanks,
D.
--
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]