Lorin Hochstein
Lorin Hochstein

Reputation: 59202

Simplifying an xpath expression used by selenium

I've got the following XPath expression that I call from selenium (technically, from splinter, which is calling selenium):

//label[text()="data"]/following-sibling::div/input|//label[text()="data"]/following-sibling::div/textarea

Is there a way to simplify this expression? The following doesn't work in selenium, although it seems to work in AquaPath:

//label[text()="data"]/following-sibling::div/(input|textarea)

Upvotes: 4

Views: 344

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243449

Try:

//label[text()="data"]/following-sibling::div/*[self::input or self::textarea]

Whenever there are many (more than 3 alternatives), an expression like this is considerably shorter:

someExpr/*[contains('|name1|name2|name3|name4|', concat('|',name(), '|'))]

Upvotes: 4

Related Questions