ロードされたページからすべてのリンクをクロールし、すべての要求および応答ヘッダーを応答本文とともに XML または txt などのファイルに記録するクローラーを作成しようとしています。最初に読み込まれたページからすべてのリンクを新しいブラウザー ウィンドウで開いているため、このエラーは発生しません。
Element not found in the cache - perhaps the page has changed since it was looked up
リクエストを作成し、すべてのリンクから応答を受け取り、開いているすべてのウィンドウから入力要素を見つけてボタンを送信する別の方法を知りたいです。開いたウィンドウの右上隅にhttp://www.testfire.netのような一般的なサイト検索ボックスがある場合を除いて、上記をある程度行うことができます。私がやりたいのは、このような一般的なボックスを省略してi.send_keys "value"
、webdriver のメソッドを使用して他の入力に値を入力し、このエラーが発生しないようにすることです。エラー: キャッシュに要素が見つかりません - ページが検索されてから変更された可能性があります。 .
Web サイトのほとんどのページに表示される一般的な入力タグで値が繰り返し入力されないように、開いている各ウィンドウから入力タグを検出して区別する方法は何ですか。私のコードは次のとおりです。
require 'rubygems'
require 'selenium-webdriver'
require 'timeout'
class Clicker
def open_new_window(url)
@driver = Selenium::WebDriver.for :firefox
@url = @driver.get " http://test.acunetix.com "
@link = Array.new(@driver.find_elements(:tag_name, "a"))
@windows = Array.new(@driver.window_handles())
@link.each do |a|
a = @driver.execute_script("var d=document,a=d.createElement('a');a.target='_blank';a.href=arguments[0];a.innerHTML='.';d.body.appendChild(a);return a", a)
a.click
end
i = @driver.window_handles
i[0..i.length].each do |handle|
@driver.switch_to().window(handle)
puts @driver.current_url()
inputs = Array.new(@driver.find_elements(:tag_name, 'input'))
forms = Array.new(@driver.find_elements(:tag_name, 'form'))
inputs.each do |i|
begin
i.send_keys "value"
puts i.class
i.submit
rescue Timeout::Error => exc
puts "ERROR: #{exc.message}"
rescue Errno::ETIMEDOUT => exc
puts "ERROR: #{exc.message}"
rescue Exception => exc
puts "ERROR: #{exc.message}"
end
end
forms.each do |j|
begin
j.send_keys "value"
j.submit
rescue Timeout::Error => exc
puts "ERROR: #{exc.message}"
rescue Errno::ETIMEDOUT => exc
puts "ERROR: #{exc.message}"
rescue Exception => exc
puts "ERROR: #{exc.message}"
end
end
end
#Switch back to the original window
@driver.switch_to().window(i[0])
end
end
ol = Clicker.new
url = ""
ol.open_new_window(url)
Selenium Webdriverまたはhttp.set_debug_output
rubyを使用して、応答本文を含むすべてのrequeatおよび応答ヘッダーを取得する方法を教えてくださいnet/http
。