NoMethodError for innerText

Hello,

I’m new to all of this. I have a script that behaves rather erratically.

I’m getting the following error…

  1. Error:
    test_capital_by_division(SampleTest):
    NoMethodError: undefined method innerText' for nil:NilClass X:/SOM/Admin/Finance/Reporting/Cognos/QA/scripts/DEV/working/CAPTEST.rb:71:i n test_capital_by_division’

This refers to the following line in my code:

assert_equal(“$977,352” ,
@b.element_by_xpath(“//form/table/tbody/tr[3]/td/div/div/table/tbody/tr[2]/td/div/div/div/table/tbody/tr[165]/td[2]/span[1]”).innerText
)

The weird thing is that there are other parts in this script where the
very some logic is used and it has no problems. So the results are
entirely inconsistent. My first test case I have set up with 4 very
similar assert_equal’s passes with flying colors.

The script in its entirety is as follows. Do I need to include a require
& include for innerText at the beginning of my script? I’m using Ruby
1.8.7-p334. Any suggestions?


require “rubygems”
require “watir”
require ‘watir/testcase’

Watir::Browser.default = 'ie'

class SampleTest < Watir::TestCase
def setup
@b ||= Watir::Browser.new
#STEP 2.01
@b.goto
http://cognosdev/cognos8/cgi-bin/cognosisapi.dll?b_action=xts.run&m=portal/cc.xts&m_tab=i0D37DF4134554CE997ED0203AACDFF12&m_folder=i0D37DF4134554CE997ED0203AACDFF12&m_folder2=m-i5D0916051581447C9DB14987546469DE
assert(@b.link(:text, “OHSU Financial Reporting”).exist?, “STEP 2.01
FAILED: URL Not Accessible”)
#STEP 2.02
assert(@b.link(:text, “OHSU Financial Reporting”).exist?, “STEP 2.01
FAILED: URL Not Accessible”)
@b.link(:text, “OHSU Financial Reporting”).click
assert(@b.link(:text, “Departmental Reports”).exist?, “STEP 2.02
FAILED: Unable to locate - Departmental Reports”)
@b.link(:text, “Departmental Reports”).click
assert(@b.link(:text, “SoM Reports”).exist?, “STEP 2.02 FAILED: Unable
to locate - SoM Reports”)
@b.link(:text, “SoM Reports”).click
assert(@b.link(:text, “Capital Expenditures & Remaining
Budget”).exist?, “STEP 2.02 FAILED: Unable to locate report”)
@b.link(:text, “Capital Expenditures & Remaining Budget”).click
@b.link(:text, “Capital Expenditures & Remaining Budget”).exist?

end

def test_capital_by_department

set the specific period to filter for

@b.cell(:text => ‘Period:’).wait_until_present
@b.select_list(:xpath,
“//input[@name=‘p_Period’]/following-sibling::*//select”).select_item_in_select_list(:value,
‘DEC-09’)
@b.execute_script(‘oCV_NS_.promptAction(“finish”)’)
@startTime = Time.now

wait until AJAX is complete

@b.cell(:text => ‘GRAND TOTAL’).wait_until_present
@endTime = Time.now
@TestRunTime = (@endTime - @startTime).round
puts @TestRunTime
puts “seconds”
assert(@TestRunTime < 30.0, “Report run time took longer than allotted
time”)

#check the various revenue numbers for Revenue and Transfers
assert_equal(“$977,352” ,
@b.element_by_xpath(“//form/table/tbody/tr[3]/td/div/div/table/tbody/tr[2]/td/div/div/div/table/tbody/tr[50]/td[2]/span[1]”).innerText
)
assert_equal(“$356,233” ,
@b.element_by_xpath(“//form/table/tbody/tr[3]/td/div/div/table/tbody/tr[2]/td/div/div/div/table/tbody/tr[50]/td[4]/span[1]”).innerText
)
assert_equal(“$621,119” ,
@b.element_by_xpath(“//form/table/tbody/tr[3]/td/div/div/table/tbody/tr[2]/td/div/div/div/table/tbody/tr[50]/td[6]/span[1]”).innerText
)
assert_equal(“36.4%” ,
@b.element_by_xpath(“//form/table/tbody/tr[3]/td/div/div/table/tbody/tr[2]/td/div/div/div/table/tbody/tr[50]/td[8]/span[1]”).innerText
)

puts “All tests passed for Capital by Department”
end

def test_capital_by_division

set the specific period to filter for

@b.cell(:text => ‘Period:’).wait_until_present
@b.select_list(:xpath,
“//input[@name=‘p_Period’]/following-sibling:://select").select_item_in_select_list(:value,
‘DEC-09’)
@b.select_list(:xpath, "//input[@name=‘p_Report
Type’]/following-sibling::
//select”).select_item_in_select_list(:value,
‘Division’)
@b.execute_script(‘oCV_NS_.promptAction(“finish”)’)
@startTime = Time.now

wait until AJAX is complete

@b.cell(:text => ‘Period:’).wait_until_present
@endTime = Time.now
@TestRunTime = (@endTime - @startTime).round
puts @TestRunTime
puts “seconds”
assert(@TestRunTime < 60.0, “Report run time took longer than allotted
time”)

#check the various revenue numbers for Revenue and Transfers
assert_equal(“$977,352” ,
@b.element_by_xpath(“//form/table/tbody/tr[3]/td/div/div/table/tbody/tr[2]/td/div/div/div/table/tbody/tr[165]/td[2]/span[1]”).innerText
)

puts “All tests passed for Capital by Division”
end

def teardown
@b.close
end
end

On 15 July 2011 20:42, Chad W. [email protected] wrote:

Hello,

I’m new to all of this. I have a script that behaves rather erratically.

I’m getting the following error…

  1. Error:
    test_capital_by_division(SampleTest):
    NoMethodError: undefined method `innerText’ for nil:NilClass

Note the wording above carefully.

X:/SOM/Admin/Finance/Reporting/Cognos/QA/scripts/DEV/working/CAPTEST.rb:71:i
n `test_capital_by_division’

This refers to the following line in my code:

assert_equal(“$977,352” ,

@b.element_by_xpath(“//form/table/tbody/tr[3]/td/div/div/table/tbody/tr[2]/td/div/div/div/table/tbody/tr[165]/td[2]/span[1]”).innerText

The error is saying that you tried to call nil.innerText. That means
that your call to element_by_xpath returned nil.

Colin