簡體   English   中英

無法自動將表格機械化為紅寶石

[英]Can not fill automatically form with mechanize on ruby

我正在嘗試測試寶石的機械化。 我想使用表格訂閱網站。 我正確地選擇了所有元素(我想),但是“提交”按鈕沒有提交表單。 提交表單后,會立即收到一封郵件。 我是該寶石的新手,並且正在測試使用一個必填字段來注冊到網站。 我正在使用webservice來檢查垃圾郵件是否正常工作,因此每個郵件字段都可以用@ moncourrier.fr.nf之前的內容替換,然后再檢查是否在yopmail網站上收到了郵件,但是我什么也沒收到。 您知道為什么不起作用嗎?

require 'rubygems'
require 'mechanize'
require'pry'


agent = Mechanize.new
agent.get('http://blackburnecreek.com/newsletter-registration') do |page|
form=agent.page.forms[1]
button=form.button_with(:value => "Subscribe")
agent.page.forms[1]["EMAIL"]= "testmechanizegem@moncourrier.fr.nf"

agent.submit(form, button)


end

您的表單沒有提交,因為實際的表單使用的是jquery,它會提交帶有一些額外參數的表單。 他們解除了表單的Submit事件的綁定,並且正在執行ajax請求以提交表單,而沒有額外的parad id

您可以通過在瀏覽器的“網絡”標簽中查看正在發起的請求來進行確認,該請求包含以下參數:

在此處輸入圖片說明 該頁面還運行以下javascript,它將額外的id參數添加到請求中:

function mce_init_form(){
    jQuery(document).ready( function(jQuery) {
      var options = { errorClass: 'mce_inline_error', errorElement: 'div', onkeyup: function(){}, onfocusout:function(){}, onblur:function(){}  };
      var mce_validator = jQuery("#mc-embedded-subscribe-form").validate(options);
jQuery("#mc-embedded-subscribe-form").unbind('submit');//remove the validator so we can get into beforeSubmit on the ajaxform, which then calls the validator
      options = { url: 'http://blackburnecreek.us8.list-manage.com/subscribe/post-json?u=68692d660a16c9b7e4be6f51e&id=f19ba31349&c=?', type: 'GET', dataType: 'json', contentType: "application/json; charset=utf-8",

參見上面函數中的url:部分。 因此,當您通過機械化提交時,您執行的是無效請求(無參數ID)。

我猜機械化不支持JavaScript的執行。 我建議您使用capybara,它使用諸如poltergiest之類的網絡驅動程序來促進對js執行的支持。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM