使用getControl到控制对象不是名称的其他变量
题
我使用它已经在我的最后一个问题被推荐Zope的testbrowser。我现在面临的问题是,我可以使用getControl函数来控制等不同的对象:密码,用户名等
我想提交页面才能到下一个页面,但提交按钮没有“名”的变量,只是一个“身份证”的变量。 “提交”被写为如下:
<input type="submit" id="lgn_button" class="button" tabindex="3" accesskey="s" />
和其他对象被写成:
<input type="password" class="button" name="password" id="password" size="24" maxlength="20" accesskey="p" tabindex="2" value=""/></td>
我没有访问改变这一点。我使用获得的“密码”对象的控制蟒的zope代码是:
browser.getControl(name='password')
在提交按钮不具有“名称”,所以我已经写:
browser.getControl(id='lgn_button')
此打印出错误的 'id' 是无效的:
TypeError: getControl() got an unexpected keyword argument 'id'
是否有任何方式来获得在“提交”另一个值中的一个的控制。
感谢您的帮助。
解决方案
我认为,对于某种原因,你不能在“名称”属性添加到您的标签,但如果它只是一个“名称”,你可以不加,你可以明确地设置“值=提交”(而不是依赖于默认的,这是提交),然后使用browser.getControl(‘提交’)
如果做不到这一点,你可以做沿东西线
for form in browser.mech_browser.forms(): for control in form.controls: if control.id == 'lgn_button': return control
您甚至可以想Browser.getControl()的扩展,并有助于回zope.testbrowser。 ;)
不隶属于 StackOverflow