【发布时间】:2020-10-07 13:50:42
【问题描述】:
我经常使用这个网站,但我从来没有遇到过提问。现在我被屏蔽了,所以是时候问第一个了。
我需要测试一个使用 vue 2 和 vuetify 创建的注册表单,服务器端使用 ruby on rails,webpack 5 渲染。 我用 selenium chrome 无头驱动程序配置了 capybara,它在与文本字段和按钮交互时工作,但是当我尝试选中复选框时:
(byebug) check('Accept')
*** Capybara::ElementNotFound Exception: Unable to find visible checkbox "Accept" that is not disabled
Vuetify 隐藏输入并将其替换为漂亮的 div 但是,检查 v-checkbox 的最佳方法是什么?
如果我添加了 visible 属性,则会找到输入但没有任何反应。我想我需要与其他元素进行交互?
(byebug) check('Accept', visible: false)
#<Capybara::Node::Element tag="input" path="/HTML/BODY[1]/DIV[1]/DIV[1]/DIV[1]/MAIN[1]/DIV[1]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/FORM[1]/DIV[2]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/INPUT[1]">
我也试过了,但仍然没有任何反应:
(byebug) page.find('input[type=checkbox]', visible: false).set(true)
#<Capybara::Node::Element tag="input" path="/HTML/BODY[1]/DIV[1]/DIV[1]/DIV[1]/MAIN[1]/DIV[1]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/FORM[1]/DIV[2]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/INPUT[1]">
所以我也尝试了点击的方式,但得到了这个错误:
(byebug) page.find('input[type=checkbox]', visible: false).click
*** Selenium::WebDriver::Error::ElementClickInterceptedError Exception: element click intercepted: Element <input aria-checked="false" id="input-96" role="checkbox" type="checkbox" value=""> is not clickable at point (234, 531). Other element would receive the click: <div class="v-input--selection-controls__ripple"></div>
(Session info: headless chrome=85.0.4183.121)
我也尝试执行原始脚本:
page.execute_script("window.uiApp.$data.terms_and_conditions = true")
vue app是这样挂载的:
window.uiApp = new Vue({
i18n,
vuetify,
store,
router,
el: id,
render: h => h(App, {
props
})
})
但是window.uiApp.$data是空的,所以这个尝试似乎也失败了:(如何访问vue组件数据(没有vue web工具)?
我不知道还有什么可以尝试的,在此先感谢
【问题讨论】:
-
用于显示“漂亮”复选框的 HTML 是什么,用户实际点击的是哪个元素?
标签: ruby-on-rails selenium vue.js capybara vuetify.js