First of all, I would say we should know about XPATH, yes the question comes to the mind What is XPATH ? Let's see the technical definition of XPath :
- “XPATH is used to find information in an XML and also used to find address element in any document or logical structure.”
- When we talk about XPath in selenium, it means we are finding element address from a web page.there are several ways to finding an element address from a web page.
Some of are following:
- By ID : ID is an attribute of any element in web page like there is an element say
<div id=”order”> here order is the id and the selenium syntax for finding element by ID would be :
- By CSS : CSS is Cascade style sheet is used for formatting the documents written is markup languages like HTML. like here we can use CSS address in selenium and it looks like (#q38 > div.qa-q-view-main > form > div.qa-q-view-content > div)
can be used like :
driver.findElement(By.cssSelector("#q38 > div.qa-q-view-main > form > div.qa-q-view-content > div"))
- By XPath : XPath is the path which locates an element in web page, It is already explained above in the starting of answer, It looks like
it can be used in selenium like :
These are the mainly used methods to finding element address in selenium rather than these other methods are also available in selenium like ,By.linktext, by.Name , By.partiallink etc.
I hope this information would help you!