Question

Need help in clicking an image that is with a td inside a table. The table is defined as

html is below:

`<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>`

I tried the below:

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

I get the error message- >"Watir::Exception::UnknownObjectException: unable to locate element, using {:id=>"imgLookup1", :tag_name=>"img"}

I then tried

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

and again the same error message. Please help!

Was it helpful?

Solution

The page-object-gem and watir treat input elements of type "image" (ie <input type="image">) as buttons.

The element should be located if you change your page object accessor to use button:

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

Note that then you can click the input using lookup1 instead lookup1_element.click.

Here is a working example:

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top