如何获取文本框的位置

时间:2019-02-03 09:31:46

标签: c# selenium xpath

我是Selenium的新手,尝试使用Xpath获取文本框,但由于无法找到字符串路径而无法正常工作。

这就是我要尝试的:

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

这是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>

我想在此位置添加一些文本

1 个答案:

答案 0 :(得分:0)

尝试以下xpath://input[@placeholder='Enter place or airport']
然后首先使用click方法单击它,然后可以在输入字段中发送值。