How to Handle Dynamic Changing IDs inside a span



  • How to Handle Dynamic Changing IDs inside a span In XPath? for example :

      <span id="listv2_f40a0e90dbcc089cae10d48a489619ee_total_rows" style="margin-left: 1px;">2000</span>
    

    In this xpath id value "f40a0e90dbcc089cae10d48a489619ee" is changing every time when reloading the page.

    Is there any way to handle this type of situation in Selenium? Below is the outer HMTL , where I need to extract the text 2000 present in total_rows

    <div class="vcr_controls">
        <input aria-label="Skip to row" id="listv2_f40a0e90dbcc089cae10d48a489619ee_first_row" aria-describedby="f40a0e90dbcc089cae10d48a489619ee_description_of_skip_to" class="list_row_number_input form-control  " autocomplete="off" title="" style="color:rgb(72, 85, 99); display:inline; height:21px" disabled="" data-original-title="Skip to row">
            <span class="sr-only" id="f40a0e90dbcc089cae10d48a489619ee_description_of_skip_to">Showing rows 1 to 1 of 1</span>
            <span style="margin-left: 5px;" class=" list_row_number_input ">
                        to
                <span id="listv2_f40a0e90dbcc089cae10d48a489619ee_last_row" style="margin-left: 1px; margin-right: 1px">1</span>
                        of
                <span id="listv2_f40a0e90dbcc089cae10d48a489619ee_total_rows" style="margin-left: 1px;">2000</span>
            </span>
        </div>
    


  • Assuming "*total_rows" is unique and constant - I think this should work to get to the span:

    "//span[contains(@id, 'total_rows')]"



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2