selenium xpath

XPATH in selenium


Basic xpath format is:

Xpath=//tagname[@attribute='value]

where

//: Select current node.

Tagname: Tagname of the particular node.

@: Select attribute.

Attribute: Attribute name of the node.

Value: Value of the attribute.

So one can run below to find all elements with robot-id = robot1 and return the span element within it. 

The * here just math any element.

    driver.find_element_by_xpath("//*[@robot-id='robot1']//span")

For vague search, use 'contains'

    Xpath=//*[contains(@name,'btn')]


or 'starts-with'

    Xpath=//*[starts-with(@name,'btn')]


use 'and' 'or' conditions

    Xpath=//*[@type='submit' or @name='btnReset']