gpt4 book ai didi

ruby-on-rails - Capybara::ElementNotFound:无法找到可见的选择框

转载 作者:数据小太阳 更新时间:2023-10-29 08:56:39 25 4
gpt4 key购买 nike

我有一个简单的引导模式,当用户单击链接时,它会显示一个带有下拉菜单和提交按钮的表单。我尝试在 Rspec 功能测试中使用 Capybara 从下拉菜单中选择选项,但它没有找到下拉菜单。

功能规范:

scenario "User searches records" do
visit my_records_path

click_link 'Search Records'

within('#practiceSearchModal') do
select('Pennsylvania', from: '#state_search')
click_on('Submit')
end
end

页面上的模式:

<div class="modal fade in" id="practiceSearchModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false" style="display: block;"><div class="modal-backdrop fade in" style="height: 654px;"></div>
<div class="modal-dialog" style="width: 750px;">
<div class="modal-content">

<select name="state" id="state_search" class="form-control">
<option value="">Select</option>
<option value="Pennsylvania">Pennsylvania</option>
<option value="New York">New York</option>
</select>



</div>
</div>
</div>

这是我在使用 Capybara 时遇到的错误,它无法找到 ID 为 state_search 的选择菜单:

 Capybara::ElementNotFound:
Unable to find visible select box "#state_search" that is not disabled within #<Capybara::Node::Element tag="div" path="/html/body/div[1]/div[2]/div[4]/div[1]/div[2]/div/div[1]/form/div">
# /home/myuser/.rvm/gems/ruby-2.1.7@core/gems/capybara-2.18.0/lib/capybara/node/finders.rb:314:in `block in synced_resolve'

但是我在页面上看到了元素:

enter image description here

为什么 capybara 点击链接后找不到我在屏幕上看到的元素?

最佳答案

from 选项采用 id,而不是 CSS 选择器 -

select('Pennsylvania', from: ‘state_search')

关于ruby-on-rails - Capybara::ElementNotFound:无法找到可见的选择框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53662424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com