0

I am not able to find the element in the selenium webdiver with java the Details are given below. I had used all class as given below in addition to Xpath:

<a href="#">
    <span>
        <i class="fa fa-users"></i>
        Employee
    </span>
    <span class="left-menu-list-right-icon">
        <i class="fa fa-chevron-right" aria-hidden="true"></i>
    </span>
</a>

Xpath is given as below

.//*[@id='sidebar-menu']/ul/li[2]/a

The element is not found

Kate Paulk
  • 31,513
  • 8
  • 54
  • 108
user24669
  • 9
  • 1

1 Answers1

1

Assuming there is no easier way and nothing unique about the elements here, the way I would do this is to first retrieve all elements containing at least one child with class selector "fa-users" (note: I am using pseudo-code - the calls may not be exactly correct):

elements = browser.findElements(By.Class, "fa-users").Parent();

Next, I would loop through the list of parent elements to find the one with inner text that contains the word "Employee", something like:

if element.InnerText().Contains("Employee") then element.Click();

The reason I would use this method is that it looks like this application uses dynamically generated DOM elements, which means that the XPath you found as a selector may not be the same as the XPath to the element when you run your test.

Kate Paulk
  • 31,513
  • 8
  • 54
  • 108