java - 从下面的 HTML 代码中查找 idNumber 元素

标签 java html xpath selenium-webdriver selenium-chromedriver

<div id="rightContent" style="display: inline-block; width: 700px; vertical-align: top;">
                <div>
                    <h1><em class="SomethingHeading">Something</em></h1>
                </div>

<div class="content scaffold-list" role="main">
    <h1>Search</h1>



    <form action="/SomethingArchiveUI/search/search" method="post">
        <table>
            <tbody>
            <tr>
                <td>ID/Registration Number:</td>
                <td>
                    <**input type="text" name="idNumber" maxlength="20" value="" id="idNumber"**>
                </td>
            </tr>
            <tr>
                <td>Client Name:</td>
                <td>
                    <input type="text" name="clientName" maxlength="50" value="" id="clientName">
                </td>
            </tr>
            <tr>
                <td>Client Surname:</td>
                <td>
                    <input type="text" name="clientSurname" maxlength="50" value="" id="clientSurname">
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="hidden" name="_dateRange"><input type="checkbox" name="dateRange" value="true" id="dateRange"><label for="dateRange">&nbsp;Use date range?</label>
                </td>
            </tr>
            <tr>
                <td colspan="2"><p>From: <input type="text" name="fromDate" value="" maxlength="10" id="fromDate" class="hasDatepicker"> To: <input type="text" name="toDate" value="" maxlength="10" id="toDate" class="hasDatepicker"></p></td>
            </tr>
            </tbody>
        </table>
        <div style="display: inline;">
            <div id="divSubmit">
                <input type="submit" name="cmdSearch" class="buttons" value="Search" id="cmdSearch">
            </div>
            <div id="divBusy" style="display: none;">
                Busy Searching...
            </div>
        </div>
    </form>

    <table id="customerIdentificationList" style="display: block;">


    </table>
    <div id="loadingMessage" style="display: none;">
        Loading. Please wait.
    </div>
</div>


            </div>

我使用下面的代码来登录应用程序,但类似的代码似乎不适用于上面的表单。我正在尝试查找“idNumber”元素:

driver.findElement(By.xpath("//*[@id='idnumber']")).sendKeys("Username");
driver.findElement(By.xpath("//*[@id=\'password\']")).sendKeys("Password");
driver.findElement(By.xpath("//*[@id=\'submit\']")).click();

我得到的错误是:org.openqa.selenium.NoSuchElementException:没有这样的元素:无法定位元素:{“method”:“xpath”,“selector”:

期待您的回复。

最佳答案

使用:.//input[@id='idnumber']

关于java - 从下面的 HTML 代码中查找 idNumber 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47324304/

相关文章:

java - 是什么导致了 "Too Much Work On Main Thread"警告?

Java使用xpath获取xml元素值 "And"

javascript - 如何使用 puppeteer 访问文本输入字段中的当前值

java - 如何创建 Comparable 接口(interface)的对象

java - 无法在 Windows 7 64 位、Sun JDK 7 和 IntelliJ 11.1 上通过 CUDA 4.0 运行 JCUDA 0.4.1

java - 如何转换为韩文首字母

php - mysql_fetch_array(),在我的程序中不起作用

html - float 元素真的从正常的 html 流中移除了吗?

html - 如何将带有标签的输入框下的文本居中?

php - 返回数组中大于X的数字