How can I get the the location of the text box

2020-05-09 23:15发布

问题:

I'm new in Selenium and try to get the Textbox using Xpath but it's not working as it says can't find the string path.

this is what I trying:

[FindsBy(How = How.XPath,Using = ".//input[@index='0']")]
    public IWebElement SearchFlightFrom { get; set; }

this the html :

<div>
<div class="waypoint-container">
    <div class="float-left margin-right locationSelector" style="position: relative;z-index: 1">
        @Html.NgLabelFor(waypoint => waypoint.LocationLabel, new { @class = "block-display" })
        <input id="from{{$index}}" name="Location" index="{{$index}}" location-is-valid="locationIsValid" is-valid="locationIsValid" auto-complete-box get-validator-options="getLocations" on-selection="updateAutoCompleteSelection" get-auto-complete-options="locationSearch" class="airport-auto-complete waypoint-location-{{$index}}" ie-placeholder="true" ng-model="waypoint.Location" placeholder="Enter place or airport" required="" tabindex="{{getTabIndex($index,0)}}" type="text" ng-blur="onLocationChange($index)" ng-focus="onLocationFocus()"></input>
        <validation-message err-message="'Location is not valid'" is-show="locationIsValid!=null &&!locationIsValid && locationWasBlured" left="80px" top="24px" width="150px" flipped="'false'" />
    </div>
    <div class="float-left margin-right" ng-show="waypoint.ShowDate">
        @Html.NgLabelFor(waypoint => waypoint.DateLabel, new { @class = "block-display" })
        <input ng-keydown="onDatePickerWayPointBlur($event)" autocomplete="off" type="text" class="begin-trip-date date-input datepicker-padding" name="Date" data_index="{{$index}}" placeholder="ddMMMyy" ng-model="waypoint.Date" tabindex="{{getTabIndex($index,2)}}" ie_placehoder="true" ui-date="waypoint.datePickerOptions" ui-date-time-format="{{DateFormat.datepicker}}" ng-required="waypoint.ShowDate" />
    </div>
    <div class="float-left margin-right" ng-show="waypoint.ShowDate">
        <label>&nbsp;</label>
        <select ng-model="waypoint.SelectedDateType" ng-options="dateType as dateType.Text for dateType in waypoint.DateTypes"
                chosen="{width:'105px'}" disable-search="true" tabindex="100">
            <option value=""></option>
        </select>
    </div>

I want to get this location for adding some text

回答1:

Try this xpath: //input[@placeholder='Enter place or airport']
And then first click on it using click method and then you can send the value in the input field.