【发布时间】:2016-07-14 12:23:26
【问题描述】:
注意:Selenium 或 API 包装器 Splinter for Selenium 中的解决方案都可以!
我在 Twitter.com 上使用 Python 的 Splinter API 与 iframe 交互时遇到问题。
例如,
with Browser('firefox', profile_preferences= proxySettings) as browser:
#...login and do other stuff here
browser.find_by_id('global-new-tweet-button').click()
这会弹出一个弹出框来输入推文。
我如何使用 Splinter 与这个新盒子进行交互以: 1) 填写留言 2) 点击“tweet”(提交) ..当然以编程方式。
我尝试检查该元素,但它似乎没有嵌套在 iframe 内,但它以 iframe 为目标。所以我不确定如何在此弹出窗口中查找/与元素交互。
我尝试手动输入消息,然后以编程方式单击推文按钮:
browser.find_by_css('.btn.primary-btn.tweet-action.tweet-btn.js-tweet-btn').click()
..但我得到了错误:
ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
Stacktrace:
at fxdriver.preconditions.visible (file:///var/folders/z1/8rqrglqn2dj8_yj1z2fv5j700000gn/T/tmppRsJvd/extensions/fxdriver@googlecode.com/components/command-processor.js:10092)
at DelayedCommand.prototype.checkPreconditions_ (file:///var/folders/z1/8rqrglqn2dj8_yj1z2fv5j700000gn/T/tmppRsJvd/extensions/fxdriver@googlecode.com/components/command-processor.js:12644)
at DelayedCommand.prototype.executeInternal_/h (file:///var/folders/z1/8rqrglqn2dj8_yj1z2fv5j700000gn/T/tmppRsJvd/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///var/folders/z1/8rqrglqn2dj8_yj1z2fv5j700000gn/T/tmppRsJvd/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///var/folders/z1/8rqrglqn2dj8_yj1z2fv5j700000gn/T/tmppRsJvd/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)
我非常想使用 Splinter 实现我的目标,所以请不要提供替代方案,我知道还有其他方法。 提前谢谢!
【问题讨论】:
标签: javascript python selenium iframe splinter