Selenium WebDriver如何将文本插入字段

时间:2015-12-26 17:06:23

标签: java selenium testing selenium-webdriver

我在Selenium WebDriver Framwework中设计测试,我想在登录框中的字段中插入文本。

这是一个网站www.fitandjump-widzew.pl 点击右上角的“Zaloguj”按钮后,会出现“登录”框。 我想将文本插入电子邮件输入字段。

这是我的代码:

WebElement emailInput =   driver.findElement(By.xpath("//[@id=\"inputFields\"]"));
emailInput.click();
emailInput.sendKeys("grzegorzrudniak@gmail.com");

执行后我收到此错误: org.openqa.selenium.ElementNotVisibleException:元素不可见

有人可以帮我在此字段中插入文字吗? 请看一下这个方框中的第二个输入,它叫做“Hasło”。 这两个字段的Xpath是一样的。 另外一个问题是如何将文本插入“Hasło”输入字段?

1 个答案:

答案 0 :(得分:0)

确保您使用的定位器识别单个元素[Unique]。在xpath中使用单引号并使用正确的xpath,在//之后我没有使用任何html标记我已经使用*,这意味着它对所有HTML标记都有效。

WebElement emailInput =   driver.findElement(By.xpath("//*[@id='inputFields']"));
//emailInput.click(); // no need to click on the element, you can directly type.
emailInput.sendKeys("grzegorzrudniak@gmail.com");