-1
<span class="icon-holder">
            <i class="c-brown-500 ti-package"></i>
        </span>
        <span class="title">Vehicle Import</span>

There have a lot of classes with "title" name. I was trying to figure out the proper xpath for this one. I have tried the following xpaths. None of them work.

driver.findElement(By.xpath("//span[contains(@class,'title') and contains(text(),'Vehicle Import')]")).click();
driver.findElement(By.xpath("//span[@class='title']")).click();
driver.findElement(By.xpath("//span[@class='title' and text()='Vehicle Import']"));

Can you guide me how to write the proper one?

1
  • Why is the title hyphenated? Is the hyphenation related to the question is some way? Maybe I'm missing something... Commented Jul 5, 2023 at 1:40

2 Answers 2

0

This is a challenging situation when we have multiple attributes inside a tag. I would recommend below locators to get out of this situation:

  • //span[normalize-space()='Vehicle Import']
  • //span[descendant::span[@class='title' and text()='Vehicle Import']]

When we encounter such kind of situations, we generally discuss them in our automation strategy meetings. Hope this information is helpful for you!!!!

0

These are the common issues faced by everyone in software qa company. Below XPath identifies the siblings of the context node.

//span/following-sibling::span[@class='title' and contains(text(),'Vehicle Import')]

By using above XPath, you should be able to locate the web element with the desired span successfully.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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