how to get the element with text in xpath1.0

27 Views Asked by At

when i use text as follow , but it doesn't work

//button[contains(text(),"Project Association")]

how to get the element "button" with specific text in xpath 1.0

<div data-v-e252fc6a="" class="toolbar">
    <button data-v-e252fc6a="" type="button" tabindex="1" class="aui-button aui-button--default">
        <!---->
        <!---->
        <i data-v-e252fc6a="" class="aui-svg associate"></i>
        " 
            Project Association
           "
    </button>
    <button data-v-e252fc6a="" type="button" tabindex="1" class="aui-button aui-button--default">
        <!---->
        <!---->
        <i data-v-e252fc6a="" class="aui-svg dissociate"></i>
                " 
            Cancel Project Management
           "
        </button>
</div>

//button[contains(text(),"Project Association")]

1

There are 1 best solutions below

4
Chewbacca On

Have you tried using the "Normalize-Space" element instead of your "contains" element?

I would suggest you try the following:

//button[normalize-space() = 'Project Association']

This should select the element with the text "Project Association" in your example code.

Otherwise you can try:

//button[text()='Project Association']