Selenium WebDriver Java - 无法填写表单中的输入字段
Selenium WebDriver Java - Cannot fill out input field in a form
我正在尝试使用 .sendKeys(…)
填写表单中的 input
字段。
HTML 我正在与:
<tr>
<td class="multi-line required" style="min-width:120px;">Name:</td>
<td>
<div style="position:relative">
<span style="display:inline-block">
<input type="text" id="_96a1fa0eccfaf628" size="40" maxlength="64" placeholder="" name="96a1fa0eccfaf628" value="">
</span>
<font class="error">*</font>
</div>
</td>
</tr>
我使用的代码:
driver.findElement(By.id("_96a1fa0eccfaf628")).sendKeys("Test Org 002");
我也试过By.name("96a1fa0eccfaf628")
,但是不行
我得到的错误:http://pastebin.com/tZ8FSwqx
元素 ID 是动态命名为“_96a1fa0eccfaf628”还是始终是 ID 的名称?如果它是动态命名的,例如名称会在每个会话中更改,那么这可能是您的问题。如果该元素始终称为“_96a1fa0eccfaf628”,那么我会尝试使用 "type" 命令或使用单击命令单击该字段,然后执行 sendKeys 命令,在每个步骤之间暂停 400 毫秒,看看如果可行的话。
我也有类似的问题。首先点击输入元素,然后清除,最后发送密钥。
driver.findElement(By.XX("your_selector")).click();
driver.findElement(By.XX("your_selector")).clear();
然后编写您的 sendKeys 函数。
您的定位器似乎有问题(ID 和名称都有一些动态和随机值)。试试下面的定位器
By.xpath("//td[contains(text(),'Name')]/following-sibling::td//input[@type='text']")
我正在尝试使用 .sendKeys(…)
填写表单中的 input
字段。
HTML 我正在与:
<tr>
<td class="multi-line required" style="min-width:120px;">Name:</td>
<td>
<div style="position:relative">
<span style="display:inline-block">
<input type="text" id="_96a1fa0eccfaf628" size="40" maxlength="64" placeholder="" name="96a1fa0eccfaf628" value="">
</span>
<font class="error">*</font>
</div>
</td>
</tr>
我使用的代码:
driver.findElement(By.id("_96a1fa0eccfaf628")).sendKeys("Test Org 002");
我也试过By.name("96a1fa0eccfaf628")
,但是不行
我得到的错误:http://pastebin.com/tZ8FSwqx
元素 ID 是动态命名为“_96a1fa0eccfaf628”还是始终是 ID 的名称?如果它是动态命名的,例如名称会在每个会话中更改,那么这可能是您的问题。如果该元素始终称为“_96a1fa0eccfaf628”,那么我会尝试使用 "type" 命令或使用单击命令单击该字段,然后执行 sendKeys 命令,在每个步骤之间暂停 400 毫秒,看看如果可行的话。
我也有类似的问题。首先点击输入元素,然后清除,最后发送密钥。
driver.findElement(By.XX("your_selector")).click();
driver.findElement(By.XX("your_selector")).clear();
然后编写您的 sendKeys 函数。
您的定位器似乎有问题(ID 和名称都有一些动态和随机值)。试试下面的定位器
By.xpath("//td[contains(text(),'Name')]/following-sibling::td//input[@type='text']")