html - 如何使用 Capybara 在 lightbox/fancybox 中查找元素

标签 html css ruby cucumber capybara

识别到我的灯箱后,如何访问其中的内容?

当我输入时:

within("div.fancybox-wrap.fancybox-desktop.fancybox-type-iframe.fancybox-opened") do
    within(:xpath, "//table[@id='small_calendar'][0]") do
        page.find('td', :text => '5').click
    end
end

为了

<table id="small_calendar">

我明白了...

Unable to find xpath "//table[@id='small_calendar'][0]" (Capybara::Element
NotFound)

修改后的搜索....

sleep(10)
within("div.fancybox-wrap.fancybox-desktop.fancybox-type-iframe.fancybox-opened") do
    within_frame('fancybox-frame') do
        #within(:xpath, ".//table[@id='small_calendar'][0]") do
            page.find(:xpath, ".//table[@id='small_calendar'][0]/td[@text='5']").click
        #end
    end
end

给我这个错误...

  findElements execution failed;
   Element does not exist in cache (Selenium::WebDriver::Error::StaleElement
ReferenceError)

最佳答案

如果元素在框架内,则必须使用 within_frame 方法明确声明:

within_frame('fancybox-frame') do
    within(:xpath, "//table[@id='small_calendar']") do
        page.find('td', :text => '5').click
    end
end

关于html - 如何使用 Capybara 在 lightbox/fancybox 中查找元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13712223/

相关文章:

html - 部署后响应式设计在 iPhone 上不起作用

css - float div 和右对齐

ruby - 查找字符串中所有连续单词组

ruby-on-rails - Rspec 格式将参数发布到字符串值

ruby - 如何对使用 RSpec 的 REST API 的方法进行单元测试?

html - 防止背景在 .dropdown-toggle 组件上改变颜色

php - HTML/CSS : Could this be achieved with a list or table?

php - 如何检查我的网站的安全性?

CSS/SCSS/bootstrap::override bootstrap::change background:transparent 中的打印设置!对颜色很重要

css - 向线性渐变填充 div 添加双边框也会使边框着色