如何使用selenium webdriver java在搜索条件字段中输入值?

时间:2013-01-02 08:21:33

标签: selenium-webdriver

我面临一个奇怪的问题,即我的脚本无法在搜索条件屏幕中输入数据 注意:这是同一个屏幕,而不是弹出窗口或新窗口。它只是导航到具有相同webdriver实例的其他屏幕

HTML:

<td class="dataCol requiredInput">

<input tabindex="1" maxlength="40" type="text" id="search_criteria" size="20" name="search_criteria" value="">

</td>

我使用的代码:

LoginPage2.driver.findElement(
  By.xpath("//input[@id='search_criteria']")
).sendKeys("test")

我正在使用Selenium 2.25.0

观察:在HTML语法如下所述的字段中编写文本值时,我不会遇到任何问题:

<*td class="dataCol col02">
<*input id="00N20000001LwsL" maxlength="20" name="00N20000001LwsL" size="20" tabindex="6" type="text">
<*/td>

我不确定这是因为HTML格式还是构建代码的方式。

请告诉我,如果我遗失了什么?我已经尝试了By.name

1 个答案:

答案 0 :(得分:-1)

driver.findElement(By.name("password")).sendKeys("ccc");