【发布时间】:2011-11-23 23:29:40
【问题描述】:
所以,我对如何在 Selenium 中执行此操作感到非常困惑,并且无法在任何地方找到答案,所以我分享我的经验。
我试图选择一个 iframe 并且没有运气(或者无论如何都不能重复)。 HTML 是:
<iframe id="upload_file_frame" width="100%" height="465px" frameborder="0" framemargin="0" name="upload_file_frame" src="/blah/import/">
<html>
<body>
<div class="import_devices">
<div class="import_type">
<a class="secondary_button" href="/blah/blah/?source=blah">
<div class="import_choice_image">
<img alt="blah" src="/public/images/blah/import/blah.png">
</div>
<div class="import_choice_text">Blah Blah</div>
</a>
</div>
</div>
</body>
</html>
Python 代码(使用 selenium 库)试图通过以下方式找到这个 iframe:
@timed(650)
def test_pedometer(self):
sel = self.selenium
...
time.sleep(10)
for i in range(5):
try:
if sel.select_frame("css=#upload_file_frame"): break
except: pass
time.sleep(10)
else: self.fail("Cannot find upload_file_frame, the iframe for the device upload image buttons")
我能找到的所有 Selenium 命令组合都重复失败。
偶尔的成功是不可复制的,所以也许是某种竞争条件或什么?从来没有找到正确的方法将它放入硒中。
【问题讨论】:
标签: python selenium xpath iframe css-selectors