views:

145

answers:

3

Hi everyone,

When I use SeleniumRC,sometimes I meet a error, but sometimes not. I guess it's related to the time of wait_for_page_to_load(), but I don't know how long will it need?

The error information:

Exception: Timed out after 30000ms
File "C:\Users\Herta\Desktop\test\newtest.py", line 9, in <module>
  sel.open(url)
File "C:\Users\Herta\Desktop\test\selenium.py", line 764, in open
  self.do_command("open", [url,])
File "C:\Users\Herta\Desktop\test\selenium.py", line 215, in do_command
  raise Exception, data

This is my program:

from selenium import selenium

url = 'http://receptome.stanford.edu/hpmr/SearchDB/getGenePage.asp?Param=4502931&amp;ProtId=1&amp;ProtType=Receptor#'

sel = selenium('localhost', 4444, '*firefox', url)
sel.start()
sel.open(url)
sel.wait_for_page_to_load(1000)
f = sel.get_html_source()
sav = open('test.html','w')
sav.write(f)
sav.close()
sel.stop()
A: 

The "Timed out after 30000ms" message is coming from the sel.open(url) call which uses the selenium default timeout. Try increasing this time using sel.set_timeout("timeout"). I would suggest 60 seconds as a good starting point, if 60 seconds doesn't work, try increasing the timeout. Also make sure that you can get to the page normally.

from selenium import selenium

url = 'http://receptome.stanford.edu/hpmr/SearchDB/getGenePage.asp?Param=4502931&amp;ProtId=1&amp;ProtType=Receptor#'

sel = selenium('localhost', 4444, '*firefox', url)
sel.set_timeout('60000')
sel.start()
sel.open(url)
sel.wait_for_page_to_load(1000)
f = sel.get_html_source()
sav = open('test.html','w')
sav.write(f)
sav.close()
sel.stop()
Wesley Wiser
Thank you for your answer :)sel.start()sel.set_timeout('60000')sel.open(url)
Herta
A: 

I had this problem and it was windows firewall blocking selenium server. Have you tried adding an exception to your firewall?

campo
A: 

Timing is a big issue when automating UI pages. You want to make sure you use timeouts when needed and provide the needed time for certain events. I see that you have

sel.open(url)
sel.wait_for_page_to_load(1000)

The sel.wait_for_page_to_load command after a sel.open call is redundant. All sel.open commands have a built in wait. This may be the cause of your problem because selenium waits as a part of the built in process of the sel.open command. Then selenium is told to wait again for the page to load. Since no page is loaded. It throws an error.

However, this is unlikely since it is throwing the trace on the sel.open command. Wawa's response above may be your best bet.

Tim Harrison