Question

I'm currently developing some tests using Selenium RC. I have to problem regarding selenium Xpath "OR" statement with xpath input and textareas. Getting to the point. I have designed 2 xpaths

textarea: //span[text()='{0}']/parent::*/following-sibling::*//textarea

input: //span[text()='{0}']/parent::*/following-sibling::*//input

Generally im using Selenium.Type(myXpath,"label=myValue"); and both of those xpaths works ok. Problem is when i was trying to merge them. I doesn't really make a difference to me if its an input or a textarea since both methods do exacly the same thus i tried to merge them with | (or) statement.

//span[text()='{0}']/parent::*/following-sibling::*//textarea|//input

but unfortunately it doesn't work. If the order is //textarea|//input it matches textarea and if //input|//textarea it matches inputs. I was trying various combinations and still nothing. Am i missing brackets or some required syntax? Thank you for all the help.

Était-ce utile?

La solution

Fetch all nodes (*), then test the element names for the ones you want using predicates.

//span[text()='{0}']/parent::*/following-sibling::*//*[local-name() = 'textarea' or local-name() = 'input']

If your XPath engine has no support for local-name() (which seems to be a problem with Selenium, see comments), you will have to repeat the complete statement:

//span[text()='{0}']/parent::*/following-sibling::*//textarea | //span[text()='{0}']/parent::*/following-sibling::*//input

The query you've been trying to use is equivalent to

(//span[text()='{0}']/parent::*/following-sibling::*//textarea) | (//input)

Which also explains the results of switching textarea and input.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top