failing to get_elements_by_xpath

Asked by Jon Rosen

Short first test using google to get the hang of SST...

To reproduce:
  from sst.actions import *
  go_to('http://www.google.com/')
  write_textfield('gbqfq','butler rosen hair san jose', True, True)
  simulate_keys('gbqfq', 'ENTER')
  wait_for(assert_title_contains,'butler rosen hair san jose')
  vals = get_elements_by_xpath('//ol[@id="rso"]//div/li')
  print vals

Results:

  (SST)jfr@jfr-linux:/home/python$ sst-run test
  Tests running...
    DEBUG:SST:Starting browser (attempt: 1)
    DEBUG:SST:Cannot connect to process 12368 with port: 35117, count 1
    DEBUG:SST:Browser started: firefox
    DEBUG:SST:Going to... http://www.google.com/
    DEBUG:SST:Waiting for 'get_element'
    DEBUG:SST:Writing to textfield u'gbqfq' with text 'butler rosen hair san jose'
    DEBUG:SST:Check text wrote correctly
    DEBUG:SST:Simulating keypress on u'gbqfq' with 'ENTER' key
    DEBUG:SST:Waiting for 'assert_title_contains'
  test ... []
    DEBUG:SST:Stopping browser
  OK (8.103 secs)

  Ran 1 test in 8.103s
  OK

So it did everything and from sst's perspective the test worked, but the print val statement returned an empty list. If you run the XPATH expression "//ol[@id="rso"]//div/li" by itself on the results from google in FirePath, you get all the li's of the output from the google search.

I think I should be getting back 10 elements in my val list but I am obviously missing something simple. Any help would be helpful!

Jon

PS - this looks like a pretty cool tool which wraps most of the selenium functionality in nice pythonic methods. But it has to work :-)

Question information

Language:
English Edit question
Status:
Solved
For:
selenium-simple-test Edit question
Assignee:
No assignee Edit question
Solved by:
Jon Rosen
Solved:
Last query:
Last reply:
Revision history for this message
Jon Rosen (jfr) said :
#1

Hi all,

Okay, I figured this out myself :-) I was waiting on the wrong thing. The title apparently gets handled very quickly and SST can beat the browser in its rendering if it assumes that the title means other stuff on the page is ready. I changed it to actually wait for the element I was looking for (the //ol tag with an id of "rso") and voila, everything comes back fine now.

Thanks!

Revision history for this message
Jon Rosen (jfr) said :
#2

Hi all,

Okay, I figured this out myself :-) I was waiting on the wrong thing. The title apparently gets handled very quickly and SST can beat the browser in its rendering if it assumes that the title means other stuff on the page is ready. I changed it to actually wait for the element I was looking for (the //ol tag with an id of "rso") and voila, everything comes back fine now.

Thanks!

Here is the changed script:

  from sst.actions import *
  go_to('http://www.google.com/')
  write_textfield('gbqfq','butler rosen hair san jose', True, True)
  simulate_keys('gbqfq', 'ENTER')
  wait_for(assert_element,tag='ol',id='rso')
  vals = get_elements_by_xpath('//ol[@id="rso"]//div/li')
  print vals

Now I get back a list of WebElements. Perfection!