使用 getControl 控制除 name 变量以外的对象

发布于 2024-08-19 11:11:29 字数 811 浏览 4 评论 0原文

我正在使用我上一个问题中推荐的 Zope testbrowser。我面临的问题是我可以使用 getControl 函数来控制不同的对象,例如:密码、用户名等。

我试图提交页面以进入下一页,但提交按钮没有“名称”变量,只是一个“id”变量。 “提交”的写法如下:

<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>

我无权更改此设置。我用来控制“密码”对象的 python zope 代码是:

browser.getControl(name='password')

提交按钮没有“名称”,所以我写了:

browser.getControl(id='lgn_button')

这会打印出“id”无效的错误:

TypeError: getControl() got an unexpected keyword argument 'id'

有没有办法获得对“提交”中其他值之一的控制。

感谢您的任何帮助。

I am using the Zope testbrowser which has been recommended in my last question. The problem that I am facing is that I can use the getControl function to control different objects like: password, username etc.

I am trying to submit the page to get to the next page but the submit button has no 'name' variable, just an 'id' variable. 'Submit' is written as follows:

<input type="submit" id="lgn_button" class="button" tabindex="3" accesskey="s" />

and the other objects are written as:

<input type="password" class="button" name="password" id="password" size="24" maxlength="20" accesskey="p" tabindex="2" value=""/></td>

I have no access to change this. The python zope code I am using to gain control of the 'password' object is:

browser.getControl(name='password')

The submit button doesn't have 'name' so I have written:

browser.getControl(id='lgn_button')

This prints out the error that 'id' is invalid:

TypeError: getControl() got an unexpected keyword argument 'id'

Is there any way to gain control of one of the other values in 'submit'.

Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋意浓 2024-08-26 11:11:29

我假设,出于某种原因,您无法向标签添加“名称”属性,但如果您只能添加一个“名称”,则可以显式设置“值=提交”(而不是依赖默认的,即 Submit),然后使用 browser.getControl('Submit')

如果失败,您可以按照

for form in browser.mech_browser.forms():
    for control in form.controls:
        if control.id == 'lgn_button':
            return control

您甚至可能想扩展 Browser.getControl() 的方式进行一些操作并贡献它回到 zope.testbrowser。 ;)

I assume that, for one reason or another, you can't add a 'name' attribute to your tag, but if it's only a 'name' that you can't add, you can explicitly set a 'value=Submit' (instead of relying on the default one, which is Submit) and then use browser.getControl('Submit')

Failing that, you can do something along the lines of

for form in browser.mech_browser.forms():
    for control in form.controls:
        if control.id == 'lgn_button':
            return control

You might even want to extend Browser.getControl() with that and contribute it back to zope.testbrowser. ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文