Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find element by label

I have this div with label "First Name", which I want to find in my Selenium e2e test:

<div class="control-group ng-class: { 'error': isInErrorState() } ng-scope" dto-control-group="" label="First Name">
    <label class="control-label" for="FirstName">
        <span class="ng-binding">First Name</span>
        <span class="required-asterisk" ng-show="isRequired">*</span>
    </label>
    <div class="controls">
                <input type="text" id="FirstName" dto-input-validate="" name="FirstName" ng-model="qform.submission.persons[0].firstName" class="ng-scope ng-pristine ng-invalid ng-invalid-dtorule">

        <div class="inline-messages">
            <!-- ngIf: helpMsg -->
            <span class="error-inline ng-binding">This is a required field</span>
        </div>
    </div>
</div>

here's my Java code:

// XXX this returns NULL
@FindBy(xpath = "//div[@label=\"First Name\"]")
private InputElement firstName;

what's wrong here?

like image 232
Alex Avatar asked Oct 19 '25 03:10

Alex


1 Answers

I think this will work for you:

@FindBy(xpath = "//div[@label='First Name']")
like image 162
Richard Avatar answered Oct 21 '25 18:10

Richard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!