LoginSignup
1

More than 5 years have passed since last update.

SeleniumWebDriver で wait.until しても 60秒で Net::ReadTimeout になってしまう

Last updated at Posted at 2016-04-13

とあるサイトで、とある処理を自動化したくて、SeleniumWebDriverで下記のように書きました。

  • Windows8
  • ruby 2.2.2p95
driver = Selenium::WebDriver.for :firefox
driver.get("とあるURL")

button.click # とあるボタンをクリックする

wait   = Selenium::WebDriver::Wait.new(:timeout => 600) # 10分
wait.until {
  driver.find_element(:how, :what) # 表示まで2,3分かかるエレメント
}

ってやると60秒後

抜粋
Net::ReadTimeout
IO::EWOULDBLOCKWaitReadable:
A non-blocking socket operation could not be completed immediately. - read would block

というエラーになってしまいました。

SeleniumWebDriverで「要素が表示されるまで待つ」と言ったら 上記のwait.untilじゃないですか。これ以外知らないじゃないですか ←勉強不足

巡り巡って、webdriverのタイムアウトを設定する - Qiita

の記事にたどり着いて

client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 600 # 10分

driver = Selenium::WebDriver.for :firefox, :http_client => client
driver.get("とあるURL")

button.click # とあるボタンをクリックする

driver.find_element(:how, :what) # 表示まで2,3分かかるエレメント

ってやったらうまくいきました。

んー、でもみなさん client = Selenium::WebDriver::Remote::Http::Default.newこんなことしてないですよね。どういう時にこういうことになるのかな。。。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1