小编J. *_*ude的帖子

使用Splinter/Selenium与iFrames交互[Python]

注意:Selenium或API包装Splinter for Selenium的解决方案很好!

我在使用Splinter API for Python在Twitter.com上与iframe交互时遇到了问题.

例如,

with Browser('firefox', profile_preferences= proxySettings) as browser:
    #...login and do other stuff here
    browser.find_by_id('global-new-tweet-button').click()
Run Code Online (Sandbox Code Playgroud)

这会弹出一个弹出框来输入推文.

如何使用Splinter与这个新盒子进行交互:1)填写消息2)点击"推特"(提交)...当然是编程的.

我尝试检查元素但它似乎没有嵌套在iframe中,但是它以iframe为目标.所以我不确定如何在弹出窗口中找到/交互元素.

我尝试手动键入消息,然后以编程方式单击tweet按钮:

browser.find_by_css('.btn.primary-btn.tweet-action.tweet-btn.js-tweet-btn').click()
Run Code Online (Sandbox Code Playgroud)

..但我收到错误:

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)
Run Code Online (Sandbox Code Playgroud)

我非常希望使用Splinter实现我的目标,所以请不要提供替代方案,我知道还有其他方法.先感谢您!

javascript python iframe selenium splinter

5
推荐指数
1
解决办法
457
查看次数

标签 统计

iframe ×1

javascript ×1

python ×1

selenium ×1

splinter ×1