Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Splinter/Selenium与iFrame交互[Python]_Javascript_Python_Selenium_Iframe_Splinter - Fatal编程技术网

Javascript 使用Splinter/Selenium与iFrame交互[Python]

Javascript 使用Splinter/Selenium与iFrame交互[Python],javascript,python,selenium,iframe,splinter,Javascript,Python,Selenium,Iframe,Splinter,注意:硒或API包装碎片中的硒溶液都可以 我在使用SplinterAPI 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()

注意:硒或API包装碎片中的硒溶液都可以

我在使用SplinterAPI 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()
这将弹出一个弹出框来输入tweet

我如何使用Splinter与这个新盒子交互以: 1) 留言 2) 点击“推特”(提交) …当然是通过编程

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

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

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)
ElementNotVisibleException:消息:元素当前不可见,因此可能无法与之交互
堆栈跟踪:
在fxdriver.premissions.visible(file:///var/folders/z1/8rqrglqn2dj8_yj1z2fv5j700000gn/T/tmppRsJvd/extensions/fxdriver@googlecode.com/components/command processor.js:10092)
在DelayedCommand.prototype.CheckPremissions\u(file:///var/folders/z1/8rqrglqn2dj8_yj1z2fv5j700000gn/T/tmppRsJvd/extensions/fxdriver@googlecode.com/components/command processor.js:12644)
在DelayedCommand.prototype.executeInternal\uh处(file:///var/folders/z1/8rqrglqn2dj8_yj1z2fv5j700000gn/T/tmppRsJvd/extensions/fxdriver@googlecode.com/components/command processor.js:12661)
在DelayedCommand.prototype.executeInternal\u(file:///var/folders/z1/8rqrglqn2dj8_yj1z2fv5j700000gn/T/tmppRsJvd/extensions/fxdriver@googlecode.com/components/command processor.js:12666)
在DelayedCommand.prototype.execute/<(file:///var/folders/z1/8rqrglqn2dj8_yj1z2fv5j700000gn/T/tmppRsJvd/extensions/fxdriver@googlecode.com/components/command processor.js:12608)
我非常希望使用Splinter来实现我的目标,所以请不要提供替代方案,我知道还有其他方法。
提前谢谢你

您的主要问题似乎是您正在将
浏览器的结果作为元素对象处理。实际上,它是元素容器对象(即webdriver元素列表)

如果我明确引用该元素,则写入字段对我有效:

In [51]: elems = browser.find_by_id('tweet-box-global')
In [52]: len(elems)
Out[52]: 1
In [53]: elems[0].fill("Splinter Example")
In [54]:
这将为我写下“碎片示例”

按钮单击失败,因为您的css路径返回一个包含三个元素的列表,并且您正在隐式单击第一个隐藏元素。在我的测试中,实际要单击的元素是列表中的第二个元素:

In [26]: elems = browser.find_by_css('.btn.primary-btn.tweet-action.tweet-btn.js-tweet-btn')
In [27]: len(elems)
Out[27]: 3
In [28]: elems[1].click()
In [29]:
当我显式地单击第二个元素时,它不会抛出错误,并且会单击按钮

如果添加到css路径,则可以将结果缩小到仅可见模式中的按钮:

In [42]: css_path = "div.modal-tweet-form-container button.btn.primary-btn"
In [43]: elems = browser.find_by_css(css_path)
In [44]: len(elems)
Out[44]: 1
In [45]: elems.click()
In [46]:
注意,这里没有抛出异常