Ruby 加载同名框架后找不到web元素

Ruby 加载同名框架后找不到web元素,ruby,ajax,watir-webdriver,Ruby,Ajax,Watir Webdriver,我有一个关于以下代码的小问题: require 'rubygems' require "watir-webdriver" webpage = "http://www.portalinmobiliario.com/catalogo/fichas.asp?ProyectoID=4308&tp=1&op=1&iug=306&ca=1&ts=1&mn=2&or=&sf=1&sp=1" pag_detalle = Watir::Br

我有一个关于以下代码的小问题:

require 'rubygems'
require "watir-webdriver"

webpage = "http://www.portalinmobiliario.com/catalogo/fichas.asp?ProyectoID=4308&tp=1&op=1&iug=306&ca=1&ts=1&mn=2&or=&sf=1&sp=1"
pag_detalle = Watir::Browser.new :firefox
pag_detalle.goto(webpage)

if pag_detalle.frame(:id => 'iFrameFicha').table(:id => 'TableInformacionBasicaProyecto').exists? then

    pag_detalle.frame(:id => 'iFrameFicha').table(:id => 'TableInformacionBasicaProyecto').link(:id => 'btnCotizar').when_present.click

    sleep 5

    if pag_detalle.frame(:id => 'iFrameFicha').table(:id => 'Cotizar').exists? then
        puts "existe"
    end

    pag_detalle.close       
end
代码打开firefox并加载一个页面。然后单击“协作”按钮。之后,框架“iFrameFicha”会更改其内容,但无法访问其元素


错误消息表明我应该切换到容器框架,但我无法切换。

您看到的错误消息似乎是watir webdriver(或selenium webdriver)中的错误。通过快速测试,当试图访问帧中的任何内容而元素不存在时,似乎会引发异常。我相信这是一样的。我相信,这个问题中的例外是不同的,只是因为它使用的是Chrome(即如果你使用firefox来解决这个问题,你就会得到你所做的例外)

特别是,当您执行以下操作时:

if pag_detalle.frame(:id => 'iFrameFicha').table(:id => 'Cotizar').exists? then
元素不存在,它(错误地)抛出了一个异常,如上所述

当我查看页面时,共有3个表,其中没有一个表具有id

我猜你实际上想要一张有“Cotizar”类的桌子:

但是您可能希望body元素具有id“cotizar”(注意小写)

<table class="Cotizar" border="0" width="100%">
if pag_detalle.frame(:id => 'iFrameFicha').table(:class=> 'Cotizar').exists? then
<body onload="resize();ExisteMarco();" style="margin:0px;" id="cotizar" class="pageBtn">
if pag_detalle.frame(:id => 'iFrameFicha').body(:id => 'cotizar').exists? then