是否有可能与水豚与隐藏的元素进行交互? [英] Is it possible to interact with hidden elements with capybara?
问题描述
我有一个文件字段,该文件字段具有opacity: 0
,并且与假按钮重叠.伪造一种在不同浏览器中始终显示的上传按钮"是一种常见的CSS技术.
I have a file field that has opacity: 0
and is overlaping a fake button. Its a common css technic to fake a sort of "Upload button" that displays consistently across different browsers.
Capybara不允许我在该输入上调用attach_file
.错误是Selenium::WebDriver::Error::ElementNotVisibleError: Element is not currently visible and so may not be interacted with
.
Capybara doesn't allows me to call attach_file
on that input. The error is Selenium::WebDriver::Error::ElementNotVisibleError: Element is not currently visible and so may not be interacted with
.
有人知道有什么方法可以迫使水豚与不可见的元素互动吗?
Anybody knows any way to force capybara to interact with invisible elements?
答案仍然没有答案,但是我已经找到了解决方法.没什么聪明的,只是用一个简单的脚本使该元素可见
The answer is still unanswered, but I've found a work around. Nothing intelligent, just make visible the element with a simple script
page.execute_script %Q{
$('#photos').css({opacity: 1, transform: 'none'});
}
我将其记录下来.
推荐答案
您可以使用Capybara中的visible: false
属性与隐藏的元素进行交互.
You can interact with hidden elements using the visible: false
property in Capybara.
如果要单击隐藏元素,请使用:
If you want to click on hidden element use:
find("#photos", visible: false).click
不要直接使用click_button('#photo')
这篇关于是否有可能与水豚与隐藏的元素进行交互?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!