在单击表格中带有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
我收到错误消息 - &gt;“Watir :: Exception :: UnknownObjectException:无法找到元素,使用{:id =&gt;”imgLookup1“,:tag_name =&gt;”img“}
然后我尝试了
table(:lookuptab1) {div_element(:id =>'allinfo' ).table_element(:style => 'height: 100%; text-align: left;')}
并再次出现相同的错误消息。请帮忙!
答案 0 :(得分:0)
page-object-gem和watir将“image”类型的输入元素(即<input type="image">
)视为按钮。
如果您更改页面对象访问者以使用button
:
button(:lookup1, :id => 'imgLookup1')
请注意,您可以使用lookup1
而不是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>