0

当我尝试访问 text 属性时发生错误:

#Here is where my error occurs
$password=wrksheet.cells(rows,"B") ['text']

上下文中的完整示例:

#require "C:\Ruby193\lib\ruby\gems\1.9.1\gems\rack-1.4.0\lib\rack\logger.rb"
require "watir"
require "watir-webdriver"
require "test/unit"
require "win32ole"

class TC_Login < Test::Unit::TestCase

    browser = Watir::Browser.new :ff
    browser.goto "gaana.com"
    #browser.driver.manage.timeouts.implicit_wait = 10
    browser.a(:class,"closeBtn").wait_until_present
    browser.a(:class,"closeBtn").click

    def test_login

        #Define the excel file
        excel= WIN32OLE::new("excel.Application")
        wrkbook=excel.Workbooks.Open("C:\\data\\test.xls")
        wrksheet = wrkbook.worksheets(1)
        wrksheet.select     

        #read the data from excel file
        rows = 2
            while    rows <= 9
                    #Here is where my error occurs
                    $password=wrksheet.cells(rows,"B") ['text']
                    puts $field
                    $username=wrksheet.cells(rows,"A") ['text']
                    $fullname=wrksheet.cells(rows,"C") ['text']

                    browser.a(:id,"joinus").click
                    browser.text_field(:id,"fullname").set($fullname)
                    browser.text_field(:id,"email").set($username)
                    browser.text_field(:id,"Password").set($password)
                    browser.a(:id, "save" ).click

                    rows=rows+1
            end
    end
end
4

1 回答 1

1

要获取 excel 单元格的文本,方法是valueor text(两者似乎都有效,尽管我没有检查是否存在任何技术差异)。

如果您将该行(以及其他类似的行)更改为:

$password = wrksheet.cells(rows,"B").text

或者

$password = wrksheet.cells(rows,"B").value
于 2013-02-07T14:40:07.693 回答