Search code examples
seleniumxpathcucumber

XPath not working for one of the selenium scenario


HTML

<div data-testid="signin-back-button" class="white-arrow">
     <a href="/" class="back-text" onclick="backBtnClick()">
         <img class="back-arrow-white" src="/images/arrow-left-white.svg" aria-hidden="true">
              Back
      </a>
</div>

I have written xpath as

//a[@onclick='backBtnClick()']/img[contains(text(),'Back')]

Solution

  • There is not need to rely on text, please use below xpath

    //a[@onclick='backBtnClick()']//child::img[contains(@src,'images/arrow-left-white.svg')]