python - 如何使用 splinter 填充表格内的输入框?

标签 python html forms testing splinter

我的 html 结构如下:

    <table id="Table1" style="Z-INDEX: 101; LEFT: 52px; WIDTH: 407px; POSITION: absolute; TOP: 53px" width="407" cellspacing="1" cellpadding="1" border="0">
                <tbody><tr>
                    <td style="WIDTH: 102px"></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td style="WIDTH: 102px">Email</td>
                    <td>
                        <input name="TextBox1" id="TextBox1" style="width:153px;" type="text"></td>
                    <td></td>
                </tr>
                <tr>
                    <td style="WIDTH: 102px">Password</td>
                    <td>
                        <input name="TextBox2" id="TextBox2" style="width:153px;" type="password"></td>
                    <td>
                        <input name="Button1" value="Login" id="Button1" style="width:68px;" type="submit"></td>
                </tr>
                <tr>
                    <td style="WIDTH: 102px"></td>
                    <td> </td>
                    <td></td>
                </tr>
                <tr>
                    <td style="WIDTH: 102px; height: 20px;"><a href="signinup.aspx">Sign up</a></td>
                    <td style="height: 20px">
                        <a href="changepassword.aspx">Change Password</a></td>
                    <td style="height: 20px"><a href="RetrievePassword.aspx">Retrieve Password</a></td>
                </tr>
                <tr>
                    <td style="WIDTH: 102px"></td>
                    <td> </td>
                    <td></td>
                </tr>
            </tbody>
         </table>

我想访问 ID 为 TextBox1 和 TextBox2 的输入框,并填写用户名和密码。

我正在做以下(例如):

browser.fill('TextBox1', 'John')

但它返回一个错误:

splinter.exceptions.ElementDoesNotExist: no elements could be found with name "TextBox1"

有人可以帮忙吗? (我是第一次使用splinter)

最佳答案

正如您在评论中提到的,问题出在包裹盒子的框架上。像这样绕过它:

browser.visit(browser.find_by_tag('frame')[0]['src'])
browser.fill('TextBox1', 'John')

关于python - 如何使用 splinter 填充表格内的输入框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42660851/

相关文章:

python - selenium 中的窗口处理(python)

python - Matplotlib - 显示具有代表相同值的多种颜色的图例

python - 从日期时间获取一年中的小时

html - 固定大小容器中的 3 个 div : 2 have fixed size, 1 应该拉伸(stretch)

javascript - 读取单选按钮的值时,值未定义

javascript - 如何使用多个输入数字?

javascript - 重置后退按钮上的表单(Safari)

python - 如何在内存中创建文件句柄并传递给Python中的外部命令

javascript - 检测登录表单的自动填充

jquery - 如何使用 jQuery 检查是否提交了任何表单?