0

因此,当我的灯箱被识别后,我如何访问其中的内容?

当我输入:

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)
4

2 回答 2

1

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

within_frame('fancybox-frame') do
    within(:xpath, "//table[@id='small_calendar']") do
        page.find('td', :text => '5').click
    end
end
于 2012-12-04T22:45:48.210 回答
0

知道了!

问题似乎是框架内和 xpath 不能相处。一旦我从等式中删除它,我就得到了想要的结果。

within_frame('fancybox-frame') do
    #within(:xpath, ".//table[@id='small_calendar'][0]") do #chokes
    within(all("table[id='small_calendar']").first) do  #works!
         #page.find(:xpath, ".//table[@id='small_calendar'][0]/td[@text='5']").click #chokes
         page.find("td[id='2013_0_6']").click #works!
    end
end
于 2012-12-05T16:54:26.177 回答