我正在尝试机械化苹果开发门户网站“编辑iOS配置文件”中的精选设备部分,它可以在here上找到(如果你已经登录了)。
源代码如下所示:
<form name="profileEdit" method="get" action="https://developer.apple.com/services-developerportal/QH43B2/account/ios/profile/regenProvisioningProfile.action?content-type=text/x-url-arguments&accept=application/json&requestId=838c910b-f63d-843e7b1ce126&userLocale=en_US&teamId=BF5K33D" successURL="/account/ios/profile/profileDownload.action?provisioningProfileId=">
<input type="hidden" name="distributionType" value='store'/>
<input type="hidden" name="returnFullObjects" value="false"/>
<div class="nameSection">
<dl>
<dt class="selectDevices">Devices:</dt>
<dd class="selectDevices">
<div class="table">
<div class="rows">
<div><input type="checkbox" name="deviceIds" class="validate" value="8T8RG7HX" id="devices-6" ><span class="title">iPhone 4 - JC</span></div>
<div><input type="checkbox" name="deviceIds" class="validate" value="7Y9F8N47" id="devices-7" ><span class="title">iPhone 5 - DP</span></div>
<div><input type="checkbox" name="deviceIds" class="validate" value="ZNES97W7" id="devices-8" checked><span class="title">iPhone 5 - JC</span></div>
<div><input type="checkbox" name="deviceIds" class="validate" value="CRDSL7S5" id="devices-9" checked><span class="title">iPod 4 inch</span></div>
</div>
</div>
</dd>
<dd class="form-error deviceIds hidden">Please select a Device</dd>
</dl>
</div>
<div class="bottom-buttons">
<a class="button small left cancel"><span>Cancel</span></a>
<a class="button small blue right submit"><span>Generate</span></a>
</div>
</form>我想做的是勾选所有的框:
form = page.form_with(:name => 'profileEdit') or raise UnexpectedContentError
form.checkboxes_with(:name => 'deviceIds').each do |checkbox|
puts checkbox["id"] # prints correct value of devices-6...
checkbox.check
end
form.method = 'GET'
form.submit我没有收到运行时错误,但是当我刷新实际页面时,并不是所有的复选框都像我想要的那样被选中。我是不是遗漏了什么?
发布于 2013-09-17 22:30:42
据我所知,你的问题是你在设置checkboxes后访问的是实际的页面,这将不起作用。但是,如果检查submit之后返回的结果,就会发现Mechanize设置了复选框并返回了响应。
如果你想在实际的浏览器中直观地看到它,你可能需要使用Watir / Webdriver等。
发布于 2013-09-17 22:52:38
为此:
form.checkboxes_with(:name => 'deviceIds').each do |checkbox|
puts checkbox["id"] # prints correct value of devices-6...
checkbox.check
end这些结果是什么:
tmp1 = form.checkboxes_with(:name => 'deviceIds').map { |cb| cb.check }
tmp2 = form.checkboxes_with(:name => 'deviceIds').map { |cb| cb.checked? }我希望这两个版本都有[true, true, true, true]。如果不是,那么一定是有什么东西在清除它们。check()方法是在RadioButton中实现的,它确实清除了所有同名按钮的选中状态,但它应该仅限于radiobutton类型。checked属性本身是可写的,因此您可以尝试直接编写它:
form.checkboxes_with(:name => 'deviceIds').each do |cb|
cb.checked = true
end并避免页面/机械化/其他内容中可能存在的bug或不一致。这只是一个猜测,但有些东西可以尝试一下。
https://stackoverflow.com/questions/18852544
复制相似问题