我正在尝试查找图像,我正在使用带有图像exists?
的if条件,然后执行删除操作。如果不是则添加。这样做我收到以下错误..
<div class="xicGridViewport">
<table id="patetrnGrid-100228" class="xicGrid xicGridLoaded" cellspacing="0" cellpadding="0">
<colgroup>
<thead>
<tbody>
<tr id="id328" class=" xicGridRow0">
<td>
<td>
<td>
<td>
<td>
<td>
<td style="text-align: center;">
<td style="text-align: center;">
<a id="cellIconLink2a" href="#" onclick="var wcall=wicketSubmitFormById('form9', '?wicket:interface=:0:form:multiplePatternBuilderGroupBox:patternGroupbox:patetrnGrid:gridCheckGroup:xicGridContainer:xicGrid:rows:3:cells:8:cell:cellIconLink::IActivePageBehaviorListener:0:-1&wicket:ignoreIfNotActive=true', 'multiplePatternBuilderGroupBox:patternGroupbox:patetrnGrid:gridCheckGroup:xicGridContainer:xicGrid:rows:3:cells:8:cell:cellIconLink' ,null,null, function() {return Wicket.$$(this)&&Wicket.$$('form9')}.bind(this));;; return false;">
<img class="xicIcon xicIconLoaded xicIconDelete" xic:size="S" xic:icon="delete" src="/uit/xicola/2.3/img/spacer.png"> <!-- Here, where i am using if condition -->
</a>
</td>
</tr>
</tbody>
<tfoot>
</table>
</div>
pattern_builder_page.rb
class BuilderPage
include PageObject
text_field(:area, name: /area/)
select_list(:load_type, name: /loadType/)
checkbox(:link_power, name: /linkPower/)
image(:plus, css: ".xicIcon.xicIconLoaded.xicIconAdd")
image(:delete_icon, css: ".xicIcon.xicIconLoaded.xicIconDelete")
button(:delete, text: 'Delete')
def create_pattern(category, place, destination)
train_category_element.when_present
self.train_category = category
fac_place_element.when_present
self.fac_place = place
fac_destination_element.when_present
self.fac_destination = destination
wait_element.when_not_visible
refresh_element.when_present
refresh
wait_element.when_not_visible
if delete_icon_element.exists?
delete
yes_element.when_present.click
end
end
end
expected one of [String, Regexp], got 1:Fixnum (TypeError)
./lib/pages/pattern_builder_page.rb:22:in `create_pattern'
./features/step_definitions/bulk_steps.rb:30:in `/^I select "(.*?)", "(.*?)" and "(.*?)" facility and submit$/'
features\pattern_builder.feature:11:in `When I select "<category>",
"<place>" and "<destination>" facility and submit'
答案 0 :(得分:1)
根据异常消息,它来自Watir-Webdriver's ElementLocator:
VALID_WHATS = [String, Regexp]
def check_type(how, what)
case how
when :index
unless what.kind_of?(Fixnum)
raise TypeError, "expected Fixnum, got #{what.inspect}:#{what.class}"
end
else
unless VALID_WHATS.any? { |t| what.kind_of? t }
raise TypeError, "expected one of #{VALID_WHATS.inspect}, got #{what.inspect}:#{what.class}"
end
end
end
此方法显示定位器值只能是:index
定位器的数字。
这意味着在您的某个定位器中,您传递的数字不是:index
的定位器。例如,你有:
# An invalid accessor:
div(:field_name, :id => 1)
# Or what is ultimately called by Watir-Webdriver:
browser.div(:id => 1).text
根据评论,有一个xpath: 1
定位器而不是index: 1
定位器。