我想登录一个门户网站。有一个表单。但主要问题是表单中有两个提交按钮。一个值为“Normal Login”,另一个值为“Special Login for utilization”。现在我想使用“Normal Login”值的按钮提交表单。
我的红宝石代码是: -
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
page = agent.get('http://egov.wbcomtax.gov.in/DematWaybill/index.jsp')
pp page #The page view for first time
login_section= page.forms.first
user_id_value= login_section.field_with(name: "txtUserID")
user_id_value.value="******"
password_value=login_section.field_with(name: "txtPassword")
password_value.value="*********"
pp user_id_value
pp password_value
home_page=login_section.submit(login_section.button_with(:value=>'Normal Login'))
pp home_page #printing the same page
现在,当我使用home_page = login_section.submit(login_section.button_with(:value =>'Normal Login'))时,它会抛出错误。
请告诉我该怎么做。
表格是:
<form name="frmLogin" method="post">
<input type="text" class="textboxc" id="txtUserID3" name="txtUserID">
<input class="textboxc" id="txtPassword" type="password" name="txtPassword" />
<input type="submit" name="Submit" value="Normal Login" onclick="return check_user()">
<input type="Submit" value="Special Login for utilisation" onclick="return check_user2()">
</form>
请帮助我。提前谢谢你。
它再次显示页面数据。我在我的代码中提到了pp页面,然后提到了pp home_page。两者都打印相同
这是我的终端视图:
C:\Ruby22\code>ruby actual_machine_test.rb
#<Mechanize::Page
{url #<URI::HTTP http://egov.wbcomtax.gov.in/DematWaybill/index.jsp>}
{meta_refresh}
{title "DEMATERIALIZED WAYBILL- Login."}
{iframes}
{frames}
{links
#<Mechanize::Page::Link "" "idforpassword.jsp">
#<Mechanize::Page::Link "" "http://www.wb.nic.in/">
#<Mechanize::Page::Link "" "http://wbcomtax.gov.in/link.htm">
#<Mechanize::Page::Link "" "http://wbcomtax.gov.in/disclaimer.htm">}
{forms
#<Mechanize::Form
{name "frmLogin"}
{method "POST"}
{action "http://egov.wbcomtax.gov.in/DematWaybill/index.jsp"}
{fields
[text:0x1f10260 type: text name: txtUserID value: ]
[field:0x2867f84 type: password name: txtPassword value: ]}
{radiobuttons}
{checkboxes}
{file_uploads}
{buttons
[submit:0x2867e58 type: submit name: Submit value: Normal Login]
[submit:0x2867cc8 type: Submit name: value: Special Login for utilisation]}>}>
[text:0x1f10260 type: text name: txtUserID value: MARK5705]
[field:0x2867f84 type: password name: txtPassword value: mark*008]
#<Mechanize::Page
{url #<URI::HTTP http://egov.wbcomtax.gov.in/DematWaybill/index.jsp>}
{meta_refresh}
{title "DEMATERIALIZED WAYBILL- Login."}
{iframes}
{frames}
{links
#<Mechanize::Page::Link "" "idforpassword.jsp">
#<Mechanize::Page::Link "" "http://www.wb.nic.in/">
#<Mechanize::Page::Link "" "http://wbcomtax.gov.in/link.htm">
#<Mechanize::Page::Link "" "http://wbcomtax.gov.in/disclaimer.htm">}
{forms
#<Mechanize::Form
{name "frmLogin"}
{method "POST"}
{action "http://egov.wbcomtax.gov.in/DematWaybill/index.jsp"}
{fields
[text:0x28ea54c type: text name: txtUserID value: ]
[field:0x28ea3f8 type: password name: txtPassword value: ]}
{radiobuttons}
{checkboxes}
{file_uploads}
{buttons
[submit:0x28ea2cc type: submit name: Submit value: Normal Login]
[submit:0x28ea13c type: Submit name: value: Special Login for utilisation]}>}>
................................