简体   繁体   English

如何使用Selenium Webdriver在联系人表单中输入文本?

[英]How to Enter Text in Contact form using selenium Webdriver?

public static void main(String[] args)
{
WebDriver wd = new FirefoxDriver();
wd.manage().window().maximize();
wd.get("http://www.arthritisspecialityclinic.com");
WebElement link=wd.findElement(By.linkText("CONTACTS"));
link.click();
WebElement Name = wd.findElement(By.xpath(".//*[@id='contact-form']/fieldset/label[1]/span[3]"));
Name.sendKeys("sakthivel");
}

I've executed the above code for Enter text in NAME text box under contact Form in website..But the text is not typed in the specific field only shown Blank...No error also shown in web driver...Any one can help me to Fix this.... 我已经执行了上面的代码,用于在网站的联系表单下的“名称”文本框中输入文本。但是,该文本未在特定字段中键入,仅显示为空白... Web驱动程序中也未显示错误...任何人都可以帮我解决这个问题。

Your xPath is wrong. 您的xPath错误。 You should select the input tag instead of the span tag. 您应该选择input标签而不是span标签。 Try this: 尝试这个:

WebElement name = wd.findElement(By.xpath("//form[@id='contact-form']/fieldset/label[1]/input"));
name.sendKeys("sakthivel");

Suggestion: This would be a cleaner method to select the WebElement . 建议:这是选择WebElement的更干净的方法。

WebElement name = wd.findElement(By.xpath("//input[@name='name']"));
name.sendKeys("sakthivel");

暂无
暂无

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

相关问题 Selenium Webdriver 在表单中输入多行文本而不提交 - Selenium Webdriver enter multiline text in form without submitting it 有没有其他方法(不是 sendKeys)使用 selenium webdriver 将文本输入文本框? - Is there any other way(not sendKeys) to enter text into textbox using selenium webdriver? 如何使用Selenium Webdriver在具有onblur,onfocus和onkeydown属性的网页文本框中输入文本? - How to enter a text in a textbox in a webpage with onblur,onfocus and onkeydown attributes using Selenium Webdriver? 在 Eclipse 中使用 Selenium WebDriver 和 java 代码在搜索字段中输入文本后如何按“Enter” - How to press 'Enter' once text is entered in the search field using Selenium WebDriver and java code in eclipse 如何使用Java和Selenium2 / Webdriver将明天的日期输入文本字段 - How can I enter tomorrow's date into a text field using Java and Selenium2/Webdriver 如何在 selenium webdriver 的文本字段中一个一个地输入字符? - How to enter characters one by one in to a text field in selenium webdriver? 如何使用Selenium Webdriver在带有查找功能的组合框中输入信息? - How to enter information in a combo box with look up using Selenium webdriver? 如果密码样式为 display:none,如何使用 Selenium webdriver 输入密码 - How to enter password using Selenium webdriver if the password style is display:none 如何使用Java在Selenium WebDriver中按“TAB”然后按“ENTER”键? - How to press “TAB” then “ENTER” key in Selenium WebDriver using Java? 使用Selenium Webdriver如何检索日期文本 - Using Selenium Webdriver how to retrive date text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM