I am unable to find xpath of "BBB" in following span class example.

<span class="xyz"> "AAA" "BBB" "CCC" ==$0 </span>

  • Welcome to the community! We need more information before any answer can be given. Can you add the code of the site you're testing? Can you add your selenium code you are using? We simply do not have enough info to give an answer right now.
    – Lee Jensen
    Feb 4 at 22:37

2 Answers 2

<span class="xyz"> "AAA" "BBB" "CCC" ==$0 </span>

In your sample HTML, "BBB" isn't an element. It is text (substring) within the element <span></span>.

Xpaths are ment to identify elements. So if your HTML is like this,


    <span class="xyz"> "AAA" "BBB" "CCC" ==$0 </span>

Then you can use these examples to find the element with Xpath,

Full Xpath: /html/body/span

Xpath with attribute: //span[@class='xyz']

Xpath contains substring: //span[contains(text(),'BBB')]

while providing automation testing services we need to have good grip on xpath creation because in few o the applications id's and classes even if defined doesn't work. So xpath's can be more helpful in such kind of situations. we can directly create xpath for the above using text of that particular element but here we can involve class of that particular element and can create the xpath in the following manner:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.