0

以下は、selectタグから特定のオプションを選択するために使用しているコードです。

       select = driver.find_element(:id, "lang")
       wait = Selenium::WebDriver::Wait.new(:timeout => 20)
       begin
         all_options = wait.until { driver.find_elements(:tag_name => "option") }
       end
       all_options.each do |option|
             if (option.attribute("value")=="11")
                 option.click
             end
       end

私はjrubyを使用しています。IRBでコマンドを1行ずつ実行しても問題ありません。しかし、コード全体を一緒に実行すると、予期しないファイルの終わりが発生するというエラーが発生します。なぜこのエラーが発生するのですか?全体として実行した場合ではなく、コマンドごとに実行した場合に機能するのはなぜですか?どうすればこれを克服できますか?

エラーは次のとおりです-

SyntaxError: (irb):364: syntax error, unexpected end-of-file

from org/jruby/RubyKernel.java:1061:in `eval'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:158:in `eval_input'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:271:in `signal_status'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:270:in `signal_status'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:155:in `eval_input'
from org/jruby/RubyKernel.java:1392:in `loop'
from org/jruby/RubyKernel.java:1160:in `catch'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:154:in `eval_input'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:71:in `start'
from org/jruby/RubyKernel.java:1160:in `catch'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:70:in `start'
from C:\jruby-1.7.1\/bin/jirb_swing:54:in `(root)'
SyntaxError: (irb):364: syntax error, unexpected kEND

end
^
from org/jruby/RubyKernel.java:1061:in `eval'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:158:in `eval_input'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:271:in `signal_status'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:270:in `signal_status'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:155:in `eval_input'
from org/jruby/RubyKernel.java:1392:in `loop'
from org/jruby/RubyKernel.java:1160:in `catch'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:154:in `eval_input'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:71:in `start'
from org/jruby/RubyKernel.java:1160:in `catch'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:70:in `start'
from C:\jruby-1.7.1\/bin/jirb_swing:54:in `(root)'
SyntaxError: (irb):367: syntax error, unexpected end-of-file

from org/jruby/RubyKernel.java:1061:in `eval'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:158:in `eval_input'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:271:in `signal_status'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:270:in `signal_status'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:155:in `eval_input'
from org/jruby/RubyKernel.java:1392:in `loop'
from org/jruby/RubyKernel.java:1160:in `catch'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:154:in `eval_input'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:71:in `start'
from org/jruby/RubyKernel.java:1160:in `catch'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:70:in `start'
from C:\jruby-1.7.1\/bin/jirb_swing:54:in `(root)'
NameError: undefined local variable or method `option' for main:Object
from (irb):367:in `evaluate'
from org/jruby/RubyKernel.java:1061:in `eval'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:158:in `eval_input'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:271:in `signal_status'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:270:in `signal_status'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:155:in `eval_input'
from org/jruby/RubyKernel.java:1392:in `loop'
from org/jruby/RubyKernel.java:1160:in `catch'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:154:in `eval_input'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:71:in `start'
from org/jruby/RubyKernel.java:1160:in `catch'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:70:in `start'
from C:\jruby-1.7.1\/bin/jirb_swing:54:in `(root)'
SyntaxError: (irb):368: syntax error, unexpected kEND

end
    ^
from org/jruby/RubyKernel.java:1061:in `eval'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:158:in `eval_input'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:271:in `signal_status'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:270:in `signal_status'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:155:in `eval_input'
from org/jruby/RubyKernel.java:1392:in `loop'
from org/jruby/RubyKernel.java:1160:in `catch'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:154:in `eval_input'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:71:in `start'
from org/jruby/RubyKernel.java:1160:in `catch'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:70:in `start'
from C:\jruby-1.7.1\/bin/jirb_swing:54:in `(root)'
SyntaxError: (irb):369: syntax error, unexpected kEND

 end
 ^
from org/jruby/RubyKernel.java:1061:in `eval'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:158:in `eval_input'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:271:in `signal_status'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:270:in `signal_status'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:155:in `eval_input'
from org/jruby/RubyKernel.java:1392:in `loop'
from org/jruby/RubyKernel.java:1160:in `catch'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:154:in `eval_input'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:71:in `start'
from org/jruby/RubyKernel.java:1160:in `catch'
from C:/jruby-1.7.1/lib/ruby/1.8/irb.rb:70:in `start'
from C:\jruby-1.7.1\/bin/jirb_swing:54:in `(root)'
4

1 に答える 1

0

エンドが多すぎます:

 begin <--- remove this
     all_options = wait.until { driver.find_elements(:tag_name => "option") }
   end <--- remove this
   all_options.each do |option|
         if (option.attribute("value")=="11")
             option.click
         end
   end

または、救助が必要な場合:

 begin
     all_options = wait.until { driver.find_elements(:tag_name => "option") }
  rescue
     do someting
  end 
   all_options.each do |option|
         if (option.attribute("value")=="11")
             option.click
         end
   end
于 2012-12-31T08:09:38.720 に答える