开发者

wrong number of arguments (1 for 0) (ArgumentError)

I am trying to find whether a text in a table of a page using Watir.

Parts of the table:

<td class="left"><a class="xoName" name="Basket Case" href="View.aspx?contactID=2D67AD97-7486-4DB9-AB83-A2C76B116618">Basket Case</a>
</td>
<td class="left" onclick="parent.location='View.aspx?contactID=2D67AD97-7486-4DB9-AB83- A2C76B116618'">shop@basketcase.co</td>

and here is the code that I used:

if b1.text(:xpath =>'/html/body/form/div[2]/div/div[3]/div[4]/table/tbody/tr[2]/td[2]/a').include?(@fullName)
  puts "  Test Passed. Found the contact: " + @fullName + ".  Actual Results match Expected Results."
else
  puts "  Test Failed! Could not find contact: " + @fullName
end

and the error message that I got:

C:/Ruby192/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.3.4/lib/watir-webdriver/browser.rb:94:in `text': wrong number of arguments (1 for 0) (ArgumentError)
    from C:/Ruby192/scripts/watir/highrise-welli.rb开发者_运维知识库:71:in `<main>'

Any help is appreciated


I generally do all I can to avoid using xpath as it is slow tends to create unreadable code and getting the paths right is tricky.

consider creating a regular expression and using that to specify the element you are looking for along with the .exists method. This presumes you know how to identify the table you are searching, and the text is contained in a single cell in the table.

targettext = Regexp.new(@fullName)
if browser.table(:how, 'what').cell(:text, targettext).exists? 
  puts 'success message'
else
  puts 'fail message'
end

If you are not reading in @fullname and it can be hard coded, then you can skip a step and just specify inline

  if browser.table(:how, 'what').cell(:text, /textyouaresearchingfor/).exists? 


For the example/error pair, the text method does not take args.

in `text': wrong number of arguments (1 for 0) (ArgumentError)

As soon as it says "arguments", look at the method you are using.

Additionally, using rspec gem, means writing less code. Then you can do this (see below) instead of rolling your own error handling.

targettext = Regexp.new(@fullName)
browser.table(:how, 'what').cell(:text, targettext).exists?.should == true

Now you only have two lines of code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜