python - 如何使用 Selenium webdriver 在网站上选择 'username' 字段?

标签 python selenium

我只想输入用户名和密码...

我试过:

username=driver.find_element(By.CSS_SELECTOR("UserId"))
username.send_keys("test")

但它给了我错误:

username=driver.find_element(By.CSS_SELECTOR("UserId"))
TypeError: 'str' object is not callable

我只是复制并粘贴了下面表格的源代码。

<form name="loginform" id="loginform" method='POST' action="login.jsp" AUTOCOMPLETE="off">

<table class="loginmiddletable" cellspacing=8 cellpadding=2>
    <tr>
        <td style="padding-top:20px" class="loginlabel">Network ID&nbsp;
            <INPUT type="text" class="logininput" value='' name="UserId" >
        </td>
    </tr>
    <tr>
        <td class="loginlabel">Password&nbsp;
            <INPUT type=password class="logininput" value='' name="Password" >
        </td>
    </tr>
    <tr>
        <td align="right" class="errormsgstyle">&nbsp;
            <input class=loginbutton type=submit name="btnLogin" value='Sign In' title="Click To Sign In" onclick="window.status='Signing in. Please wait...';">
        </td>
    </tr>
    <tr>
        <td align="left" class="errormsgstyle">&nbsp;
        </td>
    </tr>
</table>
</form>

最佳答案

find_element 方法需要 2 个参数:

username=driver.find_element(By.NAME, "UserId")
username.send_keys("test")

您也可以使用 find_element_by_name

username=driver.find_element_by_name("UserId")
username.send_keys("test")

关于python - 如何使用 Selenium webdriver 在网站上选择 'username' 字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37395517/

相关文章:

python - PySide2 Signal 无法接收 QObject 参数

python - FastAPI 中间件查看响应

python - 比较不同词典中的列表并匹配相似之处

python - 如何按值对 Python dict 的键进行排序

javascript - selenium phantomjs 无法抓取网站机器人检测

python - 使用 numpy 计算集合均值的更好方法

python-2.7 - Selenium Python 测试批处理文件未在任务计划程序中运行,浏览器未打开。批处理文件在没有任务计划程序的情况下运行正常

java - 在哪里可以找到 ax with java 指南?

iphone - Selenium iOS 驱动程序

java - Selenium 无法在 iframe 中定位元素