undefined 方法 'text' for nil:NilClass (NoMethodError) 和 被执行的操作



我有以下代码:

def find_status(arg)
    10.times do
      table = table_element(:css => 'css.path')
      break if table.visible?
    end
    table = table_element(:css => 'css.path')
    if table.visible?
      table.each do |row|
        STDOUT.puts row[1].text
        match = /^#{arg}n(String S+) at .+/.match(row[1].text)
        return match[1] if match
      end
    end
    return "status unknown"
  end

现在问题是我遇到以下错误:

undefined method `text' for nil:NilClass (NoMethodError)

奇怪的部分是它准确地打印了我想要的打印内容,并指出错误在" stdout"行上。因此,总而言之,它是执行命令,但说行是一个零值。

将不胜感激。

如果我正确理解这一点,请先对nil进行测试,然后如果存在行,请使用行文本。

STDOUT.puts row[1] ? row[1].text : 'nil'

最新更新