【发布时间】:2014-08-19 11:54:04
【问题描述】:
我正在尝试单击一个按钮来授权访问,但它似乎不起作用。会不会是 JavaScript 和机械化问题?该页面的 HTML 代码声明需要启用 JavaScript 才能“利用该网站的功能”。
这是我尝试过的:
require 'mechanize'
m = Mechanize.new
auth_page = m.get('http://www.narek.nl/ecommerce/admin/oauth_authorize?oauth_callback=http%3A%2F%2Fwww.narek.nl%2Fecommerce&oauth_token=3bda9a0a5ed8debd87c926b8cb2f31f6')
# # =>
# #<Mechanize::Page
# {url
# #<URI::HTTP:0x007ff594791990 URL:http://www.narek.nl/ecommerce/admin/oauth_authorize?oauth_callback=http%3A%2F%2Fwww.narek.nl%2Fecommerce&oauth_token=3bda9a0a5ed8debd87c926b8cb2f31f6>}
# {meta_refresh}
# {title "Magento Administrator"}
# {iframes}
# {frames}
# {links}
# {forms
# #<Mechanize::Form
# {name nil}
# {method "POST"}
# {action "http://www.narek.nl/ecommerce/admin/oauth_authorize/index/"}
# {fields
# [hidden:0x3ffaca3a0ee4 type: hidden name: form_key value: lNSCf22s2HVdBuXz]
# [text:0x3ffaca3a0d68 type: text name: login[username] value: ]
# [field:0x3ffaca3a0b9c type: password name: login[password] value: ]
# [hidden:0x3ffaca3a09d0 type: hidden name: oauth_token value: dcff49ccbd34ad5e8ce5f8ca4d67dc26]}
# {radiobuttons}
# {checkboxes}
# {file_uploads}
# {buttons [button:0x3ffaca39dcd0 type: submit name: value: ] [button:0x3ffaca39dbf4 type: name: value: ]}>}>
form = auth_page.form_with(:action => 'http://www.narek.nl/ecommerce/index.php/admin/oauth_authorize/index/')
authorisation_button = form.buttons[0]
# => [button:0x3ffaca15089c type: submit name: value: ]
authorise = m.submit(form, authorisation_button)
# # => #<Mechanize::Page
# {url
# #<URI::HTTP:0x007ff593028600 URL:http://www.narek.nl/ecommerce/admin/oauth_authorize?oauth_callback=http%3A%2F%2Fwww.narek.nl%2Fecommerce&oauth_token=3bda9a0a5ed8debd87c926b8cb2f31f6>}
# {meta_refresh}
# {title "Magento Administrator"}
# {iframes}
# {frames}
# {links}
# {forms
# #<Mechanize::Form
# {name nil}
# {method "POST"}
# {action "http://178.62.173.99/index.php/admin/oauth_authorize/index/"}
# {fields
# [hidden:0x3ffacb001774 type: hidden name: form_key value: pvWnuhmmADOfmvbk]
# [text:0x3ffacb001620 type: text name: login[username] value: ]
# [field:0x3ffacb0014cc type: password name: login[password] value: ]
# [hidden:0x3ffacb001350 type: hidden name: oauth_token value: dcff49ccbd34ad5e8ce5f8ca4d67dc26]}
# {radiobuttons}
# {checkboxes}
# {file_uploads}
# {buttons [button:0x3ffacb000a7c type: submit name: value: ] [button:0x3ffacb0009b4 type: name: value: ]}>}>
当我尝试提交authorisation_button 时,它只会刷新当前页面。当我访问授权网址时,它仍然显示授权按钮。如果授权成功,按钮应该不会显示。
这就是 HTML 的样子:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Magento Admin</title>
<link rel="icon" href="http://www.narek.nl/ecommerce/skin/adminhtml/default/default/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="http://www.narek.nl/ecommerce/skin/adminhtml/default/default/favicon.ico" type="image/x-icon"/>
<script type="text/javascript">
var BLANK_URL = 'http://www.narek.nl/ecommerce/js/blank.html';
var BLANK_IMG = 'http://www.narek.nl/ecommerce/js/spacer.gif';
var BASE_URL = 'http://www.narek.nl/ecommerce/index.php/admin/index/index/key/491c19cb98a4e669b0f21b52089840a7/';
var SKIN_URL = 'http://www.narek.nl/ecommerce/skin/adminhtml/default/default/';
var FORM_KEY = 'GGvnhfOGCuVG25a2';
</script>
<link rel="stylesheet" type="text/css" href="http://www.narek.nl/ecommerce/skin/adminhtml/default/default/reset.css" media="all" />
<link rel="stylesheet" type="text/css" href="http://www.narek.nl/ecommerce/skin/adminhtml/default/default/boxes.css" media="all" />
<link rel="stylesheet" type="text/css" href="http://www.narek.nl/ecommerce/skin/adminhtml/default/default/custom.css" media="all" />
<link rel="stylesheet" type="text/css" href="http://www.narek.nl/ecommerce/skin/adminhtml/default/default/xmlconnect/boxes.css" media="all" />
<link rel="stylesheet" type="text/css" href="http://www.narek.nl/ecommerce/skin/adminhtml/default/default/print.css" media="print" />
<script type="text/javascript" src="http://www.narek.nl/ecommerce/js/prototype/prototype.js"></script>
<script type="text/javascript" src="http://www.narek.nl/ecommerce/js/scriptaculous/effects.js"></script>
<script type="text/javascript" src="http://www.narek.nl/ecommerce/js/prototype/validation.js"></script>
<script type="text/javascript" src="http://www.narek.nl/ecommerce/js/mage/translate.js"></script>
<script type="text/javascript" src="http://www.narek.nl/ecommerce/js/mage/adminhtml/form.js"></script>
<script type="text/javascript" src="http://www.narek.nl/ecommerce/js/mage/adminhtml/tools.js"></script>
<!--[if lt IE 8]>
<link rel="stylesheet" type="text/css" href="http://www.narek.nl/ecommerce/skin/adminhtml/default/default/iestyles.css" media="all" />
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="http://www.narek.nl/ecommerce/skin/adminhtml/default/default/below_ie7.css" media="all" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="http://www.narek.nl/ecommerce/skin/adminhtml/default/default/ie7.css" media="all" />
<![endif]-->
<!--[if lte IE 8]>
<link rel="stylesheet" type="text/css" href="http://www.narek.nl/ecommerce/skin/adminhtml/default/default/xmlconnect/iestyles.css" media="all" />
<![endif]-->
<script type="text/javascript">
Fieldset.addToPrefix(1);
</script>
<script type="text/javascript">//<![CDATA[
var Translator = new Translate([]);
//]]></script></head>
<body class="page-popup adminhtml-oauth-authorize-index">
<div>
<noscript>
<div class="noscript">
<div class="noscript-inner">
<p><strong>JavaScript seems to be disabled in your browser.</strong></p>
<p>You must have JavaScript enabled in your browser to utilize the functionality of this website.</p>
</div>
</div>
</noscript>
<div class="login-container auth-confirm">
<div class="login-box">
<div class="login-form auth-confirm">
<div class="page-title">
<h1>Authorize application</h1>
</div>
<h2><strong>Admin</strong> requests access to your account</h2>
<p>After authorization application will have access to you account.</p>
<form id="oauth_authorize_confirm" action="http://www.narek.nl/ecommerce/index.php/admin/oauth_authorize/confirm/" method="get">
<input type="hidden" name="oauth_token" value="3bda9a0a5ed8debd87c926b8cb2f31f6">
<button type="submit" class="button" title="Authorize"><span><span>Authorize</span></span></button>
</form>
<form id="oauth_authorize_reject" action="http://www.narek.nl/ecommerce/index.php/admin/oauth_authorize/reject/" method="get">
<input type="hidden" name="oauth_token" value="3bda9a0a5ed8debd87c926b8cb2f31f6">
<button type="submit" class="button" title="Reject"><span><span>Reject</span></span></button>
</form>
</div>
<p class="legal">Magento is a trademark of Magento Inc. Copyright © 2014 Magento Inc.</p>
<div class="bottom"></div>
</div>
</div>
</div>
</body>
</html>
这是页面在浏览器中的样子:
如何点击Authorize 按钮?
【问题讨论】:
-
提交表单前需要设置用户名/密码。没有冒犯,但这应该是显而易见的。您应该考虑雇用某人来帮助您。
-
@pguardiario 我已将页面的屏幕截图添加到问题中。没有要填写的表格。