简体   繁体   English

Selenium WebDriver Java-无法填写表单中的输入字段

[英]Selenium WebDriver Java - Cannot fill out input field in a form

I'm trying to use .sendKeys(…) to fill out an input field in a form. 我正在尝试使用.sendKeys(…)填写表单中的input字段。

HTML I'm working with: 我正在使用的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>

The code I'm using: 我正在使用的代码:

driver.findElement(By.id("_96a1fa0eccfaf628")).sendKeys("Test Org 002");

I have also tried By.name("96a1fa0eccfaf628") , but nope. 我也尝试了By.name("96a1fa0eccfaf628") ,但是没有。

The error Im getting: http://pastebin.com/tZ8FSwqx 错误即时消息: http : //pastebin.com/tZ8FSwqx

I have a similar problem. 我有一个类似的问题。 First click in input element, then clear and finally sendkeys. 首先单击输入元素,然后清除,最后是sendkeys。

driver.findElement(By.XX("your_selector")).click();
driver.findElement(By.XX("your_selector")).clear();

Then write your sendKeys function. 然后编写您的sendKeys函数。

It seems problem with your locator (Id & name both has some dynamic & random values). 定位器似乎有问题(ID和名称都具有一些动态和随机值)。 Try with below locator 尝试使用以下定位器

By.xpath("//td[contains(text(),'Name')]/following-sibling::td//input[@type='text']")

Is the element ID Dynamically named "_96a1fa0eccfaf628" or is this always the name of the ID? 元素ID是动态命名的“ _96a1fa0eccfaf628”还是它始终是ID的名称? If it's dynamically named for example the name changes each session then that may be your issue. 例如,如果它是动态命名的,则每个会话的名称都会更改,这可能是您的问题。 If the element is always called "_96a1fa0eccfaf628" then I would try using the "type" command or using a click command to click the field and then do the sendKeys command with a small pause of say 400 ms in between each step and see if that works. 如果该元素始终被称为“ _96a1fa0eccfaf628”,那么我将尝试使用“类型”命令或单击命令来单击该字段,然后执行sendKeys命令,并在每个步骤之间稍作停顿(例如400毫秒),看看是否作品。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM