Thursday, March 14, 2013
XPath
-- XPath, the XML Path Language, is a query language for selecting nodes from an XML document.
Example:-
<input name="username"/>
<input name="password"/>
<input name="submit" and @type="submit" and @value="submit"/>
XPaths of above fields are as follows
//input[@name='username']
//input[@name='password']
//input[@name='submit' and @type='submit']
Use sendKeys() for setting values to textboxes.
Use click() to perform click action on any control on webpage.
Following is the WebDriver Java code to use the above XPaths to login:-
WebDriver driver = new InternetExplorerDriver();
WebElement element;
driver.get("http://www.dummyUrl.com");
element = driver.findElement(By.xpath("//input[@name='username']"));
element.setText("admin");
element = driver.findElement(By.xpath("//input[@name='password']"));
element.setText("pass@123");
element = driver.findElement(By.xpath("//input[@name='submit' and @type='submit']"));
element.click();
Labels:
Automation,
Testing,
WebDriver
Subscribe to:
Post Comments (Atom)
thank you meena , this helped me a lot..
ReplyDelete