I am getting XPath error. Already tried with many XPath's. But not able to resolve. Can anyone give correct XPath?


<form id="report-filter-form" class="report-filter-form" accept-charset="utf-8" method="post" autocomplete="on" action="https://nextgen.retrofit.qa.binaryfountain.com/ng/reports/hca/practice-performance-report">
<div class="form-body white-background">
<div class="row">
<input id="top_avatar" class="form-control input-md filter-top-avatar practice-performance-report" type="hidden" value="41730" name="top_avatar"/>
<div class="col-md-12 multiple-location-avatar">
<div class="form-group ">
<label class="" for="avatar_id">Select Location(s)</label>
<div id="s2id_avatar_id" class="select2-container select2-container-multi select2 filter-avatar-id multiple-location-avatar practice-performance-report valid form-control input-md">
<ul class="select2-choices">
<li class="select2-search-field">
<label class="select2-offscreen" for="s2id_autogen5">Select Location(s)</label>

    <!-- DESIRED ELEMENT -->
    <input id="s2id_autogen5" class="select2-input select2-default" type="text" spellcheck="false" autocapitalize="off" autocorrect="off" autocomplete="off" style="width: 617px;" placeholder=""/>
    <!-- DESIRED ELEMENT -->

<div class="select2-drop select2-drop-multi select2-display-none">
<select id="avatar_id" class="select2 select2-multiple filter-avatar-id multiple-location-avatar practice-performance-report valid form-control input-md select2-offscreen" value="" 0="excel_config_status" placeholder="Select Location(s)" label="Select Location(s)" multiple="multiple" block_class="col-md-12 multiple-location-avatar" name="avatar_id[]" tabindex="-1">

Highlighted path I need correct XPath. Already tried with many input XPath's and sibling XPath's.

Error Message:


1 Answer 1


The id of the input element looks auto-generated - you probably cannot use it to locate the element directly.

There are so many ways to get to the element, but I think, using the label's text and then using the following-sibling axis is one of the most explicit approaches:

//label[. = 'Select Location(s)']/following-sibling::input

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.