简体   繁体   中英

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....

Your xPath is wrong. You should select the input tag instead of the span tag. 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 name = wd.findElement(By.xpath("//input[@name='name']"));
name.sendKeys("sakthivel");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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