0

在单击表格中带有 td 的图像时需要帮助。该表定义为

html如下:

`<html class=" myapp>
 <head id="head1">
<body id="body1">
 <div id = "container" class>
  <div id = "Header" class="header">..</div>
   <div id = "navbar" class="topnavbar">..</div>
  <form name = "form1"....>
.
.
.
<div id = "Layout container" class>
  <div id="appcontectinfo">...</div>
<div class="tabcontent">
 <div id="allinfo">
   <table id="tablename"> </table>
   <table>
     <tbody>
    <tr>
     <td>
       <table id style = "height 100%">
                 <tbody>
        <tr style ="height : 16">
          <td class = "clsClassname1">
            <table cellpadding = "0" cellspacing = "0">
            <tbody>
              <tr>
                <td class = "clsMyexpClass1>
                   <input src = "https://www.mylinkhere.com/lookup.gif" name = "myimage1" type = "image" id = "imgLookup1">
                </td>`

我尝试了以下方法:

image(:lookup1, :id => 'imgLookup1')
 lookup1_element.click 

我收到错误消息->“Watir::Exception::UnknownObjectException: 无法找到元素,使用 {:id=>"imgLookup1", :tag_name=>"img"}

然后我尝试了

table(:lookuptab1) {div_element(:id =>'allinfo' ).table_element(:style => 'height: 100%; text-align: left;')}

并再次出现相同的错误消息。请帮忙!

4

1 回答 1

0

page-object-gem 和 watir 将类型为“图像”(即<input type="image">)的输入元素视为按钮。

如果您将页面对象访问器更改为使用,则该元素应该位于button

button(:lookup1, :id => 'imgLookup1')

请注意,您可以使用lookup1instead单击输入lookup1_element.click

这是一个工作示例:

class MyPage
  include PageObject

  button(:lookup1, :id => 'imgLookup1')
end

browser = Watir::Browser.new
browser.goto("data:text/html,#{DATA.read}")

page = MyPage.new(browser)
page.lookup1

browser.close

__END__

<html>
  <body>
    <input src = "https://www.mylinkhere.com/lookup.gif" name = "myimage1" type = "image" id = "imgLookup1" onclick="alert();">
  </body>
</html>
于 2013-11-20T17:35:46.980 回答