How does Selenium WebDriver find WebElement
Here's a summary of several common ways to find page elements from our team code:
(1) through the ID of WebElement
If a WebElement provides ID
(2) search through WebElement's name:
WebElement element = driver.findElement (By.name ("passwd"))
(3) search through WebElement's xpath:
WebElement element = driver.findElement (By.xpath ("/ / input [@ id='passwd-id']"))
(4) search through the style of WebElement:
CheddarGouda
You can find page elements by:
Listcheeses = driver.findElements (By.className ("cheese"))
(5) search through hyperlink text:
Cheese >
Then you can find it like this:
WebElement cheese = driver.findElement (By.linkText ("cheese"))