Interview Questions

Selenium WebDriver - What all different element locators are available with Selenium 2.0?

Selenium WebDriver Interview question and Answers


(Continued from previous question...)

Selenium WebDriver - What all different element locators are available with Selenium 2.0?

Selenium 2.0 uses same set of locators which are used by Selenium 1.0 – id, name, css, XPath but how Selenium 2.0 accesses them is different. In case of Selenium 1.0 you don’t have to specify a different method for each locator while in case of Selenium 2.0 there is a different method available to use a different element locator. Selenium 2.0 uses following method to access elements with id, name, css and XPath locator –
driver.findElement(By.id("HTMLid"));
driver.findElement(By.name("HTMLname"));
driver.findElement(By.cssSelector("cssLocator"));
driver.findElement(By. className ("CalssName”));
driver.findElement(By. linkText ("LinkeText”));
driver.findElement(By. partialLinkText ("PartialLink”));
driver.findElement(By. tagName ("TanName”));
driver.findElement(By.xpath("XPathLocator));

(Continued on next question...)

Other Interview Questions