Identifying the element by using the XML path of the HTML structure to locate the element is known as XPath.
Identifying the MobileElement by “XPath”. It takes String as an argument. If an element isn't identified it throws an exception as No Such Element Exception.
Syntax :
driver.find_element(AppiumBy.XPATH,"Locator_Value")
We have two types of XPath
Absolute XPath :
It uses a complete XML root path to the required MobileElement.
This Absolute XPath is not recommended because whenever the XML structure changes then we need to update the XPath as well every time.
Syntax :
/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.widget.LinearLayout/android.widget.EditText
'/' - finding the element inside the parent element '//' - finding the child or nested-child element inside the parent element
Relative Xpath :
It uses the direct path of a MobileElement using (id,className,attribute values , sub-string,etc) to perform action on it.
Syntax :
//android.widget.Button[@resource-id="com.skill2lead.appiumdemo:id/EnterValue"]
//tag[@attribute='value'] //android.widget.Button[@resource-id="com.skill2lead.appiumdemo:id/EnterValue"]