Reputation: 115
Just a bit curious to know if '[' has specific meaning while writing locators in selenium. Couldn't find anything on google.
ex. Xpath=//tagname[@attribute='value']
Do they represent some kind of array of elements matching the criteria or does it have some specific meaning. for ex. in json arrays are enclosed in [], something like that.
Upvotes: 0
Views: 838
Reputation: 250
In Xpath we can use [ ] for -
Ex. //tr[2] Means second tr child element on page.
Ex. //*[@title='Ok'] . -> matches to any tag having attribute "title" with value "Ok"
You can also use [ ] with Xpath axes methods.
Ex. //*[text(),'OK']
Upvotes: 1
Reputation: 106
Do not confuse the use of "[]" in Xpath with its use programming.
"[]" in programming means the index of the element
but
In Xpath "[]" brackets can be used to specify index or conditions for selecting elements . In you an example: XPath ill select element "tagname" which contains attribute having a value equal to "value".
For more details on conditions please refer: https://developer.mozilla.org/en-US/docs/Web/XPath/Snippets
Upvotes: 1