Reputation: 4072
I have the following html snippet:
<div>
<span class="gwt-InlineLabel myinlineblock" style="display: none;" aria-hidden="true">Go to row</span>
<input id="data_configuration_view_preview_ib_row" class="gwt-IntegerBox marginleft red" type="text" size="8"/>
<span class="gwt-InlineLabel error myinlineblock marginleft" style="width: 7ex;" aria-hidden="false">Error!</span>
</div>
I am trying to locate the text Error!
I start from the input id tag as that has an ID. I am not able to go down to the span tag which has the text Error!
My xpath to start from the id is:
//input[@id="data_configuration_view_preview_ib_row"]
I have tried:
//input[@id="data_configuration_view_preview_ib_row"]/span[contains(text(), "Error!")]
What CSS or XPath can I use to locate the text Error!?
I have managed to locate the element with the following Xpath:
//input[@id="data_configuration_view_preview_ib_row"]//following-sibling::span[contains(text(), "Error!")]
Thanks, Riaz
Upvotes: 2
Views: 1784
Reputation: 23825
You can use cssSelector
as :
using with error
class
span.error
using with id data_configuration_view_preview_ib_row
#data_configuration_view_preview_ib_row + span.error
OR you can use xpath
as :
using with error
class
//span[contains(@class, 'error')]
using with preceding
id data_configuration_view_preview_ib_row
//span[preceding::*[@id = 'data_configuration_view_preview_ib_row']]
using with preceding-sibling
id data_configuration_view_preview_ib_row
//span[preceding-sibling::*[@id = 'data_configuration_view_preview_ib_row']]
Hope it helps..:)
Upvotes: 1
Reputation: 42538
Use the axis following-sibling
to get the next element on the same level:
//input[@id="data_configuration_view_preview_ib_row"]/following-sibling::span
You could also use a CSS selector:
#data_configuration_view_preview_ib_row + span
Upvotes: 1