30000ms后超时

发布于 2024-09-13 11:40:35 字数 847 浏览 4 评论 0原文

当我使用 SeleniumRC 时,有时会遇到错误,但有时不会。我猜想和wait_for_page_to_load()的时间有关,但不知道需要多长时间?

错误信息:

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

这是我的程序:

from selenium import selenium

url = 'http://receptome.stanford.edu/hpmr/SearchDB/getGenePage.asp?Param=4502931&ProtId=1&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()

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&ProtId=1&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()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏末 2024-09-20 11:40:35

“30000ms 后超时”消息来自使用 selenium 默认超时的 sel.open(url) 调用。尝试使用 sel.set_timeout("timeout") 增加此时间。我建议 60 秒作为一个很好的起点,如果 60 秒不起作用,请尝试增加超时。还要确保您可以正常访问该页面。

from selenium import selenium

url = 'http://receptome.stanford.edu/hpmr/SearchDB/getGenePage.asp?Param=4502931&ProtId=1&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()

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&ProtId=1&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()
妄想挽回 2024-09-20 11:40:35

自动化 UI 页面时,计时是一个大问题。您需要确保在需要时使用超时并为某些事件提供所需的时间。我发现您

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

在 sel.open 调用之后有 sel.wait_for_page_to_load 命令是多余的。所有 sel.open 命令都有内置的等待。这可能是问题的原因,因为 selenium 作为 sel.open 命令内置进程的一部分等待。然后selenium 被告知再次等待页面加载。由于没有加载页面。它抛出一个错误。

但是,这不太可能,因为它会在 sel.open 命令上抛出跟踪。 Wawa 的上述回应可能是您最好的选择。

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.

离笑几人歌 2024-09-20 11:40:35

我遇到了这个问题,是 Windows 防火墙阻止了 Selenium 服务器。您是否尝试过向防火墙添加例外?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文