-1

这里有很多关于多个 while 循环的好信息,但没有一个适用于 .include?

我试图让下面的 while 循环工作但无济于事。我会很感激任何帮助。

while browser.text.include? 'No results found for' || browser.text.include? '- did not match any documents.'
4

2 回答 2

2

您是否可能只需要添加括号?

例如:

[22] pry(main)> a=[1]
=> [1]
[23] pry(main)> a.include? 2
=> false
[24] pry(main)> a.include?2 || a.include?3
SyntaxError: unexpected tINTEGER, expecting end-of-input
[24] pry(main)> (a.include?2) || (a.include?3)
=> false
[25] pry(main)> 
于 2013-10-31T07:48:40.557 回答
0

我真的很喜欢将数据与逻辑分开,即使我们只有两个值。

no_result_strings = ['No results found for', '- did not match any documents.']

while no_result_strings.any?{|no_result| browser.text.include?(no_result)} do
    puts 'found no result, will continue.'
end

#Or, if browser.text is a string and you want it shorter:

while no_result_strings.any?{|x|browser.text[x]} do
    puts 'found no result, will continue.'
end
于 2013-10-31T08:23:07.673 回答