making xpath find element by text in subordinate element

45 views
Skip to first unread message

Mikhail Ramendik

unread,
Apr 13, 2017, 6:01:39 PM4/13/17
to Selenium Users
Hello,

I need to click a button with some name in the class attribute and some text in it. The problem is that the text can turn out to be in a subordinate element.

And the way that I could find using google does not seem to work in this case. Here is the outerHTML of the button where this problem happens:

<span role="button" class="mblToolBarButton mblToolBarButtonHasLeftArrow" tabindex="0" id="dojox_mobile_ToolBarButton_3" dir="ltr" widgetid="dojox_mobile_ToolBarButton_3"><span class="mblToolBarButtonArrow mblToolBarButtonLeftArrow mblColorDefault mblColorDefault45"></span><span class="mblToolBarButtonBody mblColorDefault"><table cellpadding="0" cellspacing="0" border="0" role="presentation" class="mblToolBarButtonText"><tbody><tr><td class="mblToolBarButtonIcon"></td><td class="mblToolBarButtonLabel">Back</td></tr></tbody></table></span></span>

The xpath selector is:

//*[contains(@class,'mblToolBarButtonHasLeftArrow') and text()[contains(.,'Back')]]

I understand I could just find the subordinate td element itself, but this would hit any other Back button that might be present on the screen. Besides, I don't want things to break if they remove this td formatting and put the button text directly under the span element, as it is with othe rbuttons in the same UI. The id values are useless because dojo can change them between builds of the UI.
 
So how can I modify this xpath selector to ensure that text in subordinate elements is found?

Thanks!

Yours, Mikhail Ramendik

nasir mohd

unread,
Apr 16, 2017, 1:52:50 AM4/16/17
to Selenium Users
You can use this xpath selector: 
xpath= //*[text()='Back'] this will work irrespective of its position in the html.
Reply all
Reply to author
Forward
0 new messages