2013-08-30 48 views
0

我有下面的代码一点具体的问题:无法找到加载帧后的网页元素同名

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和加载页面。然后点击'Cotizar'按钮。之后,框架'iFrameFicha'改变其内容,但无法访问其元素。

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

回答

1

您所看到的错误消息看起来像watir-webdriver(或selenium-webdriver)中的错误。从快速测试看来,只要尝试访问某个框架内的任何内容(例如),该元素就不存在就会抛出异常。我相信这与Issue 211是一样的。我认为,这个问题的例外情况不同,只是因为它使用的是Chrome浏览器(即,如果您使用Firefox来解决问题,您会得到例外)。

特别是,当你的行:

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

的元素不存在,如上述提及的(错误地)抛出异常。

当我看着页面时,有3个表格,其中没有一个具有ID。

我猜你真的想与“Cotizar”表:

<table class="Cotizar" border="0" width="100%"> 

这意味着代码应该是:

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

但也许你想要的主体元素有id“cotizar”(注意小写)。

<body onload="resize();ExisteMarco();" style="margin:0px;" id="cotizar" class="pageBtn"> 

在这种情况下,你需要做的:

if pag_detalle.frame(:id => 'iFrameFicha').body(:id => 'cotizar').exists? then