How to connect nested xpaths for Selenium webdriver? Label and separate button per row

I am trying to assert that the button on our page is disabled. Below HTML is what I am working with at the moment:

<div data-persona-noeditable="" style="display: block;">
    <div class="c-potential-tooltip persona-name pull-left" data-potential-tooltip="">
        <div data-name-persona="" class="marg5" data-original-title="" title="">autoTestMapped</div>
    </div>
    <button class="btn btn-small pull-left marg5" data-copy-persona="">Copy</button>
    <button class="btn btn-small pull-left marg5" data-edit-persona="" style="display: inline-block;">Edit</button>
    <button class="btn btn-small pull-left marg5" data-persona-deactivate="" disabled="" style="display: inline-block;">Deactivate</button>
    <button class="btn btn-small pull-left marg5" data-persona-activate="" style="display: none;">Activate</button>
    <i class="fa fa-times pull-down" data-persona-delete="" style="display: none;"></i>
</div>

      

I'm trying to check if a Deactivate button is disabled or not, but I want to associate it along with the label name in the string autoTestMapped

.

This is nested in the first div and I'm having a hard time figuring out how to get Selenium to look at both of them to confirm that the button is coming with that specific user.

I've tried different options:

Assert.assertFalse("deactivate button is disabled for autoTestMapped", driver.findElement(By.xpath("//*div[contains(text(), 'autoTestMapped')]")).isEnabled());

      

including use | to connect two separate XPaths, but nothing works. I can copy the xpath location, but that is not static as the newly created user can force the list to move up or down.

Any help on this would be immensely appreciated.

+3


source to share


1 answer


following-sibling

would be helpful here:



//div[contains(@class, "persona-name") and div = "autoTestMapped"]/following-sibling::button[. = "Deactivate"]

      

+1


source







All Articles