Как найти этот элемент на веб-странице? - PullRequest
1 голос
/ 24 июня 2019

Когда я щелкаю правой кнопкой мыши и выбираю inspect element, элемент, который я хочу найти на веб-странице, имеет следующий код:

<input type="text" ng-if="!editing" ng-model="item.Price" ng-click="inputFocus()" ts="" required="" placeholder="قیمت :" class="ng-pristine ng-untouched ng-scope ng-empty ng-invalid ng-invalid-required">

Есть другие элементы с таким же кодом и такими же путями на страницетакже, и элементы не имеют определенного атрибута id.Так как же найти нужные элементы, если они имеют одинаковые коды?

РЕДАКТИРОВАТЬ: один из HTML код элемента:

<fieldset class="fieldset ui-state-default ng-scope" id="227" ng-repeat="item in $root.selectedMarketWatch" ng-class="{ fullWidth:$root.uiSettings.fullWidthTable || item.showMaxSize || openLeft }" ng-hide="item.Hide">
  <legend class="legend Saffron" style="cursor: move"><span class="title ng-binding">SAFTR98    -</span><span class="title ng-binding">قرارداد آتی زعفران نگین تحویل تیر ماه 1398                                                          </span><span class="Font Ico-info-circle sub-menu" ng-click="showSubMenu=!showSubMenu"></span>
    <i
      class="Font Ico-times" ng-click="$root.hideContract(item)"></i><i class="Font Ico-window-maximize" ng-click="fullSizeContract(item)"></i><i class="Font Ico-window-minimize" ng-click="minimizeContract(item)"></i>
      <ul class="menu-detail" ng-class="{ show:showSubMenu }">
        <li class="menu-detail-li"> سر رسید: <span class="list ng-binding">1398/04/25</span></li>
        <li class="menu-detail-li"> روز گواهی: <span class="list ng-binding">1398/04/25</span></li>
        <li class="menu-detail-li"> وجه تضمین: <span class="list ng-binding">5,000,000</span></li>
        <li class="menu-detail-li"> حداقل وجه تضمین: <span class="list ng-binding">3,500,000</span></li>
        <li class="menu-detail-li"> حداکثرحجم هر سفارش: <span class="list ng-binding">25</span></li>
        <li class="menu-detail-li"> اندازه قرارداد : <span class="list ng-binding">100 گرم</span></li>
        <li class="menu-detail-li"> حد نوسان قیمت روزانه: <span class="list ng-binding"> از 128,200 تا 141,600 </span></li>
      </ul>
  </legend>
  <div class="partition" id="topLayot" ng-class="{hide:item.showMinSize}">
    <div class="deal" ng-class="{ w100: hideBidAsk || hideTradeBox}">
      <div class="deal-label-r"><label class="deal-label" tooltip-left="" tooltip=""><!-- ngIf: !editing --><input type="text" ng-if="!editing" ng-model="item.Price" ng-click="inputFocus()" ts="" required="" placeholder="قیمت :" class="ng-pristine ng-untouched ng-scope ng-empty ng-invalid ng-invalid-required"><!-- end ngIf: !editing --><!-- ngIf: editing --><i class="Font Ico-angle-up action" ng-click="priceUp(item)"></i><i class="Font Ico-angle-down action" ng-click="priceDown(item)"></i></label>
        <label
          class="deal-label count"><input type="text" ng-model="item.Quantity" ts="" ng-keydown="quantityInputKeyPress(item,$event)" required="" placeholder="تعداد :" class="ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required"><i class="Font Ico-angle-up action" ng-click="quantityUp(item)"></i>
          <i
            class="Font Ico-angle-down action" ng-click="quantityDown(item)"></i>
            </label>
      </div>
      <div class="deal-label"><button class="contract-button buy" ng-click="sendOrder(0, item)">خرید</button><button class="contract-button cansel" ng-click="clearBoxes(item)">انصراف</button><button class="contract-button sell" ng-click="sendOrder(1, item)">فروش</button></div>
    </div>
    <!-- ngIf: !hideBidAsk -->
    <div class="partition-p1 columns ng-scope" ng-if="!hideBidAsk" ng-class="{ w100: hideTradeBox}">
      <table class="table-layot-center bid-ask-table">
        <thead>
          <tr class="secondTr">
            <th>حجم</th>
            <th>قیمت</th>
            <th>قیمت</th>
            <th>حجم</th>
          </tr>
        </thead>
        <tbody>
          <tr class="Contents">
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.BidVolume1" ng-dblclick="changeVolume(item,item.pushMarketWatchData.BidVolume1)" id="_BidVolume1" class="BidStyle ng-binding flashCell">17</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.BidPrice1" ng-dblclick="changePrice(item,item.pushMarketWatchData.BidPrice1)" id="_Bidprice1" class="BidStyle ng-binding flashCell">136,500</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.AskPrice1" ng-dblclick="changePrice(item,item.pushMarketWatchData.AskPrice1)" id="_AskPrice1" class="AskStyle ng-binding flashCell">136,900</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.AskVolume1" ng-dblclick="changeVolume(item,item.pushMarketWatchData.AskVolume1)" id="_AskVolume1" class="AskStyle ng-binding flashCell">15</td>
          </tr>
          <tr class="Contents">
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.BidVolume2" ng-dblclick="changeVolume(item,item.pushMarketWatchData.BidVolume2)" id="_BidVolume2" class="BidStyle ng-binding flashCell">63</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.BidPrice2" ng-dblclick="changePrice(item,item.pushMarketWatchData.BidPrice2)" id="_BidPrice2" class="BidStyle ng-binding flashCell">136,400</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.AskPrice2" ng-dblclick="changePrice(item,item.pushMarketWatchData.AskPrice2)" id="_AskPrice2" class="AskStyle ng-binding flashCell">137,000</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.AskVolume2" ng-dblclick="changeVolume(item,item.pushMarketWatchData.AskVolume2)" id="_AskVolume2" class="AskStyle ng-binding flashCell">11</td>
          </tr>
          <tr class="Contents">
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.BidVolume3" ng-dblclick="changeVolume(item,item.pushMarketWatchData.BidVolume3)" id="_BidVolume3" class="BidStyle ng-binding flashCell">76</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.BidPrice3" ng-dblclick="changePrice(item,item.pushMarketWatchData.BidPrice3)" id="_BidPrice3" class="BidStyle ng-binding flashCell">136,300</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.AskPrice3" ng-dblclick="changePrice(item,item.pushMarketWatchData.AskPrice3)" id="_AskPrice3" class="AskStyle ng-binding flashCell">137,100</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.AskVolume3" ng-dblclick="changeVolume(item,item.pushMarketWatchData.AskVolume3)" id="_AskVolume3" class="AskStyle ng-binding flashCell">68</td>
          </tr>
        </tbody>
      </table>
    </div>
    <!-- end ngIf: !hideBidAsk -->
    <!-- ngIf: !hideTradeBox -->
    <div class="partition-p2 columns ng-scope" ng-if="!hideTradeBox" ng-class="{ w100: hideBidAsk}">
      <table class="info-table">
        <thead>
          <tr>
            <th> اولین </th>
            <th> بالاترین </th>
            <th> پایین ترین </th>
            <th> آخرین </th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td class="unitValue ng-binding flashCell" style="cursor: pointer" flash-cell="item.pushMarketWatchData.FirstTradedPrice" id="_FirstTradedPrice" ng-dblclick="changePrice(item,item.pushMarketWatchData.FirstTradedPrice)"> 137,200 </td>
            <td class="unitValue ng-binding flashCell" style="cursor: pointer" flash-cell="item.pushMarketWatchData.HighTradedPrice" id="_HighTradedPrice" ng-dblclick="changePrice(item,item.pushMarketWatchData.HighTradedPrice)"> 137,900 </td>
            <td class="unitValue ng-binding flashCell" style="cursor: pointer" flash-cell="item.pushMarketWatchData.LowTradedPrice" id="_LowTradedPrice" ng-dblclick="changePrice(item,item.pushMarketWatchData.LowTradedPrice)"> 133,700 </td>
            <td class="unitValue bold ng-binding flashCell" style="cursor: pointer" flash-cell="item.pushMarketWatchData.LastTradedPrice" id="_LastTradedPrice" ng-dblclick="changePrice(item,item.pushMarketWatchData.LastTradedPrice)"> 136,600 </td>
          </tr>
          <tr>
            <td class="unitChange  ng-binding raiseUp flashCell" flash-cell="item.pushMarketWatchData.FirstTradedPriceChange" id="_C_FirstTradedPriceChange" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.FirstTradedPriceChange < 0, raiseUp:item.pushMarketWatchData.FirstTradedPriceChange > 0}">
            2,291 </td>
            <td class="unitChange  ng-binding raiseUp flashCell" flash-cell="item.pushMarketWatchData.HighTradedPriceChange" id="_C_HighTradedPriceChange" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.HighTradedPriceChange < 0,raiseUp:item.pushMarketWatchData.HighTradedPriceChange > 0 }">
            2,991 </td>
            <td class="unitChange  ng-binding raiseDown flashCell" flash-cell="item.pushMarketWatchData.LastTradedPriceChange" id="_C_LowTradedPriceChange" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.LowTradedPriceChange < 0,raiseUp:item.pushMarketWatchData.LowTradedPriceChange > 0 }">
            -1,209 </td>
            <td class="unitChange  ng-binding raiseUp flashCell" flash-cell="item.pushMarketWatchData.LastTradedPriceChange" id="_C_LastTradedPriceChange" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.LastTradedPriceChange < 0,raiseUp:item.pushMarketWatchData.LastTradedPriceChange > 0 }">
            1,691 </td>
          </tr>
          <tr>
            <td class="unitChange top ng-binding raiseUp flashCell" flash-cell="item.pushMarketWatchData.FirstTradedPriceChangePercent" id="_C_FirstTradedPriceChangesPercent" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.FirstTradedPriceChangePercent < 0,raiseUp:item.pushMarketWatchData.FirstTradedPriceChangePercent > 0 }">
            1.7 % </td>
            <td class="unitChange top ng-binding raiseUp flashCell" flash-cell="item.pushMarketWatchData.HighTradedPriceChangePercent" id="_C_HighTradedPriceChangesPercent" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.HighTradedPriceChangePercent < 0,raiseUp:item.pushMarketWatchData.HighTradedPriceChangePercent > 0 }">
            2.22 % </td>
            <td class="unitChange top ng-binding raiseDown flashCell" flash-cell="item.pushMarketWatchData.LowTradedPriceChangePercent" id="_C_LowTradedPriceChangesPercent" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.LowTradedPriceChangePercent < 0,raiseUp:item.pushMarketWatchData.LowTradedPriceChangePercent > 0 }">
            -0.9 % </td>
            <td class="unitChange top ng-binding raiseUp flashCell" flash-cell="item.pushMarketWatchData.LastTradedPriceChangePercent" id="_C_LastTradedPriceChangesPercent" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.LastTradedPriceChangePercent < 0 ,raiseUp:item.pushMarketWatchData.LastTradedPriceChangePercent > 0 }">
            1.25 % </td>
          </tr>
        </tbody>
      </table>
    </div>
    <!-- end ngIf: !hideTradeBox -->
    <div id="_PersianOrdersDateTime" class="date-time" title="زمان آخرین به روزرسانی سفارشات"><span flash-cell="item.pushMarketWatchData.OrdersDateTime" class="flashCellDark ng-binding flashCell"> به روز رسانی: دوشنبه 3 تیر 1398 - 16:47:28 </span></div>
    <!-- ngIf: !hideSettlementPrice -->
    <div class="partition-p3 columns ng-scope" ng-if="!hideSettlementPrice">
      <div class="readonlyForm">
        <div class="row five">
          <div class="column">
            <p class="title">قیمت تسویه لحظه ای</p>
            <p class="value ng-binding">136,062</p>
          </div>
          <div class="column">
            <p class="title">قیمت تسویه روز قبل</p>
            <p class="value ng-binding">134,909</p>
          </div>
          <div class="column">
            <p class="title">حجم</p>
            <p class="value ng-binding">5,887</p>
          </div>
          <div class="column">
            <p class="title">ارزش</p>
            <p class="value ng-binding">80,099,900</p>
          </div>
          <div class="column">
            <p class="title">موقعیت های باز</p>
            <p class="value ng-binding" style="direction: ltr"> 15,855 <span style="margin: 0px 0px 0px 15px; color: red;" ng-style="{color: item.pushMarketWatchData.OpenInterestsChanges < 0 ? 'red' : '#06B6A6' }" class="ng-binding"> -184 </span></p><span></span></div>
        </div>
      </div>
    </div>
    <!-- end ngIf: !hideSettlementPrice -->
  </div>
</fieldset>

Код другого элемента:

<fieldset class="fieldset ui-state-default ng-scope" id="229" ng-repeat="item in $root.selectedMarketWatch" ng-class="{ fullWidth:$root.uiSettings.fullWidthTable || item.showMaxSize || openLeft }" ng-hide="item.Hide">
  <legend class="legend Saffron" style="cursor: move"><span class="title ng-binding">SAFMO98    -</span><span class="title ng-binding">قرارداد آتی زعفران نگین تحویل مرداد ماه 1398                                                        </span><span class="Font Ico-info-circle sub-menu" ng-click="showSubMenu=!showSubMenu"></span>
    <i
      class="Font Ico-times" ng-click="$root.hideContract(item)"></i><i class="Font Ico-window-maximize" ng-click="fullSizeContract(item)"></i><i class="Font Ico-window-minimize" ng-click="minimizeContract(item)"></i>
      <ul class="menu-detail" ng-class="{ show:showSubMenu }">
        <li class="menu-detail-li"> سر رسید: <span class="list ng-binding">1398/05/26</span></li>
        <li class="menu-detail-li"> روز گواهی: <span class="list ng-binding">1398/05/26</span></li>
        <li class="menu-detail-li"> وجه تضمین: <span class="list ng-binding">5,000,000</span></li>
        <li class="menu-detail-li"> حداقل وجه تضمین: <span class="list ng-binding">3,500,000</span></li>
        <li class="menu-detail-li"> حداکثرحجم هر سفارش: <span class="list ng-binding">25</span></li>
        <li class="menu-detail-li"> اندازه قرارداد : <span class="list ng-binding">100 گرم</span></li>
        <li class="menu-detail-li"> حد نوسان قیمت روزانه: <span class="list ng-binding"> از 137,900 تا 152,300 </span></li>
      </ul>
  </legend>
  <div class="partition" id="topLayot" ng-class="{hide:item.showMinSize}">
    <div class="deal" ng-class="{ w100: hideBidAsk || hideTradeBox}">
      <div class="deal-label-r"><label class="deal-label" tooltip-left="" tooltip=""><!-- ngIf: !editing --><input type="text" ng-if="!editing" ng-model="item.Price" ng-click="inputFocus()" ts="" required="" placeholder="قیمت :" class="ng-pristine ng-untouched ng-scope ng-empty ng-invalid ng-invalid-required"><!-- end ngIf: !editing --><!-- ngIf: editing --><i class="Font Ico-angle-up action" ng-click="priceUp(item)"></i><i class="Font Ico-angle-down action" ng-click="priceDown(item)"></i></label>
        <label
          class="deal-label count"><input type="text" ng-model="item.Quantity" ts="" ng-keydown="quantityInputKeyPress(item,$event)" required="" placeholder="تعداد :" class="ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required"><i class="Font Ico-angle-up action" ng-click="quantityUp(item)"></i>
          <i
            class="Font Ico-angle-down action" ng-click="quantityDown(item)"></i>
            </label>
      </div>
      <div class="deal-label"><button class="contract-button buy" ng-click="sendOrder(0, item)">خرید</button><button class="contract-button cansel" ng-click="clearBoxes(item)">انصراف</button><button class="contract-button sell" ng-click="sendOrder(1, item)">فروش</button></div>
    </div>
    <!-- ngIf: !hideBidAsk -->
    <div class="partition-p1 columns ng-scope" ng-if="!hideBidAsk" ng-class="{ w100: hideTradeBox}">
      <table class="table-layot-center bid-ask-table">
        <thead>
          <tr class="secondTr">
            <th>حجم</th>
            <th>قیمت</th>
            <th>قیمت</th>
            <th>حجم</th>
          </tr>
        </thead>
        <tbody>
          <tr class="Contents">
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.BidVolume1" ng-dblclick="changeVolume(item,item.pushMarketWatchData.BidVolume1)" id="_BidVolume1" class="BidStyle ng-binding flashCell">16</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.BidPrice1" ng-dblclick="changePrice(item,item.pushMarketWatchData.BidPrice1)" id="_Bidprice1" class="BidStyle ng-binding flashCell">146,700</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.AskPrice1" ng-dblclick="changePrice(item,item.pushMarketWatchData.AskPrice1)" id="_AskPrice1" class="AskStyle ng-binding flashCell">146,800</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.AskVolume1" ng-dblclick="changeVolume(item,item.pushMarketWatchData.AskVolume1)" id="_AskVolume1" class="AskStyle ng-binding flashCell">23</td>
          </tr>
          <tr class="Contents">
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.BidVolume2" ng-dblclick="changeVolume(item,item.pushMarketWatchData.BidVolume2)" id="_BidVolume2" class="BidStyle ng-binding flashCell">73</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.BidPrice2" ng-dblclick="changePrice(item,item.pushMarketWatchData.BidPrice2)" id="_BidPrice2" class="BidStyle ng-binding flashCell">146,600</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.AskPrice2" ng-dblclick="changePrice(item,item.pushMarketWatchData.AskPrice2)" id="_AskPrice2" class="AskStyle ng-binding flashCell">146,900</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.AskVolume2" ng-dblclick="changeVolume(item,item.pushMarketWatchData.AskVolume2)" id="_AskVolume2" class="AskStyle ng-binding flashCell">22</td>
          </tr>
          <tr class="Contents">
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.BidVolume3" ng-dblclick="changeVolume(item,item.pushMarketWatchData.BidVolume3)" id="_BidVolume3" class="BidStyle ng-binding flashCell">179</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.BidPrice3" ng-dblclick="changePrice(item,item.pushMarketWatchData.BidPrice3)" id="_BidPrice3" class="BidStyle ng-binding flashCell">146,500</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.AskPrice3" ng-dblclick="changePrice(item,item.pushMarketWatchData.AskPrice3)" id="_AskPrice3" class="AskStyle ng-binding flashCell">147,000</td>
            <td style="cursor: pointer" flash-cell="item.pushMarketWatchData.AskVolume3" ng-dblclick="changeVolume(item,item.pushMarketWatchData.AskVolume3)" id="_AskVolume3" class="AskStyle ng-binding flashCell">156</td>
          </tr>
        </tbody>
      </table>
    </div>
    <!-- end ngIf: !hideBidAsk -->
    <!-- ngIf: !hideTradeBox -->
    <div class="partition-p2 columns ng-scope" ng-if="!hideTradeBox" ng-class="{ w100: hideBidAsk}">
      <table class="info-table">
        <thead>
          <tr>
            <th> اولین </th>
            <th> بالاترین </th>
            <th> پایین ترین </th>
            <th> آخرین </th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td class="unitValue ng-binding flashCell" style="cursor: pointer" flash-cell="item.pushMarketWatchData.FirstTradedPrice" id="_FirstTradedPrice" ng-dblclick="changePrice(item,item.pushMarketWatchData.FirstTradedPrice)"> 148,300 </td>
            <td class="unitValue ng-binding flashCell" style="cursor: pointer" flash-cell="item.pushMarketWatchData.HighTradedPrice" id="_HighTradedPrice" ng-dblclick="changePrice(item,item.pushMarketWatchData.HighTradedPrice)"> 148,400 </td>
            <td class="unitValue ng-binding flashCell" style="cursor: pointer" flash-cell="item.pushMarketWatchData.LowTradedPrice" id="_LowTradedPrice" ng-dblclick="changePrice(item,item.pushMarketWatchData.LowTradedPrice)"> 143,200 </td>
            <td class="unitValue bold ng-binding flashCell" style="cursor: pointer" flash-cell="item.pushMarketWatchData.LastTradedPrice" id="_LastTradedPrice" ng-dblclick="changePrice(item,item.pushMarketWatchData.LastTradedPrice)"> 146,800 </td>
          </tr>
          <tr>
            <td class="unitChange  ng-binding raiseUp flashCell" flash-cell="item.pushMarketWatchData.FirstTradedPriceChange" id="_C_FirstTradedPriceChange" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.FirstTradedPriceChange < 0, raiseUp:item.pushMarketWatchData.FirstTradedPriceChange > 0}">
            3,213 </td>
            <td class="unitChange  ng-binding raiseUp flashCell" flash-cell="item.pushMarketWatchData.HighTradedPriceChange" id="_C_HighTradedPriceChange" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.HighTradedPriceChange < 0,raiseUp:item.pushMarketWatchData.HighTradedPriceChange > 0 }">
            3,313 </td>
            <td class="unitChange  ng-binding raiseDown flashCell" flash-cell="item.pushMarketWatchData.LastTradedPriceChange" id="_C_LowTradedPriceChange" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.LowTradedPriceChange < 0,raiseUp:item.pushMarketWatchData.LowTradedPriceChange > 0 }">
            -1,887 </td>
            <td class="unitChange  ng-binding raiseUp flashCell" flash-cell="item.pushMarketWatchData.LastTradedPriceChange" id="_C_LastTradedPriceChange" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.LastTradedPriceChange < 0,raiseUp:item.pushMarketWatchData.LastTradedPriceChange > 0 }">
            1,713 </td>
          </tr>
          <tr>
            <td class="unitChange top ng-binding raiseUp flashCell" flash-cell="item.pushMarketWatchData.FirstTradedPriceChangePercent" id="_C_FirstTradedPriceChangesPercent" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.FirstTradedPriceChangePercent < 0,raiseUp:item.pushMarketWatchData.FirstTradedPriceChangePercent > 0 }">
            2.21 % </td>
            <td class="unitChange top ng-binding raiseUp flashCell" flash-cell="item.pushMarketWatchData.HighTradedPriceChangePercent" id="_C_HighTradedPriceChangesPercent" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.HighTradedPriceChangePercent < 0,raiseUp:item.pushMarketWatchData.HighTradedPriceChangePercent > 0 }">
            2.28 % </td>
            <td class="unitChange top ng-binding raiseDown flashCell" flash-cell="item.pushMarketWatchData.LowTradedPriceChangePercent" id="_C_LowTradedPriceChangesPercent" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.LowTradedPriceChangePercent < 0,raiseUp:item.pushMarketWatchData.LowTradedPriceChangePercent > 0 }">
            -1.3 % </td>
            <td class="unitChange top ng-binding raiseUp flashCell" flash-cell="item.pushMarketWatchData.LastTradedPriceChangePercent" id="_C_LastTradedPriceChangesPercent" dir="ltr" ng-class="{ raiseDown:item.pushMarketWatchData.LastTradedPriceChangePercent < 0 ,raiseUp:item.pushMarketWatchData.LastTradedPriceChangePercent > 0 }">
            1.18 % </td>
          </tr>
        </tbody>
      </table>
    </div>
    <!-- end ngIf: !hideTradeBox -->
    <div id="_PersianOrdersDateTime" class="date-time" title="زمان آخرین به روزرسانی سفارشات"><span flash-cell="item.pushMarketWatchData.OrdersDateTime" class="flashCellDark ng-binding flashCell"> به روز رسانی: دوشنبه 3 تیر 1398 - 16:49:47 </span></div>
    <!-- ngIf: !hideSettlementPrice -->
    <div class="partition-p3 columns ng-scope" ng-if="!hideSettlementPrice">
      <div class="readonlyForm">
        <div class="row five">
          <div class="column">
            <p class="title">قیمت تسویه لحظه ای</p>
            <p class="value ng-binding">146,215</p>
          </div>
          <div class="column">
            <p class="title">قیمت تسویه روز قبل</p>
            <p class="value ng-binding">145,087</p>
          </div>
          <div class="column">
            <p class="title">حجم</p>
            <p class="value ng-binding">39,418</p>
          </div>
          <div class="column">
            <p class="title">ارزش</p>
            <p class="value ng-binding">576,351,940</p>
          </div>
          <div class="column">
            <p class="title">موقعیت های باز</p>
            <p class="value ng-binding" style="direction: ltr"> 36,355 <span style="margin: 0px 0px 0px 15px; color: rgb(6, 182, 166);" ng-style="{color: item.pushMarketWatchData.OpenInterestsChanges < 0 ? 'red' : '#06B6A6' }" class="ng-binding"> 2,002 </span></p><span></span></div>
        </div>
      </div>
    </div>
    <!-- end ngIf: !hideSettlementPrice -->
  </div>
</fieldset>

Код, который я использую для теста, таков:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome("chromedriver.exe")
driver.set_page_load_timeout(10)
driver.get("https://something.com")
time.sleep(45)
login = driver.find_element_by_id("submit-btn")
login.send_keys(Keys.RETURN)
driver.refresh()

driver.set_page_load_timeout(10)
price = driver.find_element_by_xpath("//input[@class='ng-pristine ng-untouched ng-scope ng-empty ng-invalid ng-invalid-required' and starts-with(@ng-click, 'inputFocus')'][contains(@ng-model, 'Price') and @placeholder='قیمت :']")
price.send_keys("1")
price.send_keys(Keys.RETURN)
time.sleep(4)
driver.quit()

Ответы [ 4 ]

1 голос
/ 25 июня 2019

Используйте следующие уникальные xpaths:

  1. Для вашего первого HTML:

    //span[contains(text(), 'SAFTR98')]/ancestor::fieldset//input[@ng-model='item.Price']
    
  2. Для вашего второго HTML:

    //span[contains(text(), 'SAFMO98')]/ancestor::fieldset//input[@ng-model='item.Price']
    

Надеюсь, это поможет.

0 голосов
/ 24 июня 2019

Скорее всего, тот же элемент в другой ветви DOM. Попробуйте взять родительский элемент с чем-то уникальным.

В моем случае это было похоже на

//*[@id='ma-modal__body']/child::*[@ng-if='!editing']

Читайте об XPath Axes. В DOM существует множество различных взаимосвязей элементов. Надеюсь, помог!

0 голосов
/ 24 июня 2019

Вероятно, лучшим способом было бы придерживаться значения ng-model атрибута , соответствующее выражение XPath будет:

//input[@ng-model='item.Price']

Вы также можете использовать Явное ожидание , чтобы убедиться, что элемент присутствует и может взаимодействовать:

new org.openqa.selenium.support.ui.WebDriverWait(driver, 10)
        .until(
                ExpectedConditions.elementToBeClickable(
                        By.xpath("//input[@ng-model='item.Price']")))
0 голосов
/ 24 июня 2019

Чтобы найти нужный элемент, вы можете использовать любой из следующих Стратегий локатора :

  • CSS

    "input.ng-pristine.ng-untouched.ng-scope.ng-empty.ng-invalid.ng-invalid-required[ng-click^='inputFocus][ng-model$='Price'][placeholder='قیمت :']"
    
  • XPATH

    "//input[@class='ng-pristine ng-untouched ng-scope ng-empty ng-invalid ng-invalid-required' and starts-with(@ng-click, 'inputFocus')'][contains(@ng-model, 'Price') and @placeholder='قیمت :']"
    
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...