Hey guys,
I want to create xpath which will return only text and i am able to capture that element also from katalon
current scenario :
Html look like this
<div class="info">
<div class="alert" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
Success Message
</div>
</div>
I have tried with below xpath but it will return text like.
x
Success Message
//div[@class="info"]/div
it will also return cross sign from button ‘x’, i want only “Success Message”
i don’t want button text, so please suggest xpath for this
thanks!
Hello,
unfortunately it’s not possible … only way is to remove text of child using groovy script
https://groups.google.com/forum/#!topic/webdriver/3mbMXA3sdlA
If your HTML has an enclosing tag for ‘Success Message’ text, for example as follows:
<div class="info">
<div class="alert" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button>
<span>Success Message</span>
</div>
</div>
Then you write a XPath:
//div[@class="info"]/div/span
And you will get the following output:
Success Message
But in fact your HTML does not have the enclosing tag. Therefore, as Andrej pointed out, you can not write a XPath which returns “Success Message” text out of the given HTML.
actually, there is xpath that will return only text, but cannot be used anywhere (even in my support lib)
//div[@class="info"]/div/text()