从订单项列表中提取href值 [英] Extract a href value from a Line Item list

查看:60
本文介绍了从订单项列表中提取href值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从以下html中提取href值<a ng-href=.

I am trying to extract the href value <a ng-href= from the following html.

值"BJ11TFZ"是动态的.

The value "BJ11TFZ" is dynamic.

这是一个具有许多LI的UL,它将是列表中的第一项. 我希望能够捕获它,所以我可以构建一个单击的URL

It is a UL with many LI, it will be the first item in the list. I want to be able to capture it so i can construct a url to click

 <!-- Begin Results List -->
  <ul id="resultsLists" class="o-media-list  c-animate  c-animate--show" ng-show="rc.results.vehicles.length" style="">
    <li id="BJ11TFZ" class="c-animate  c-animate--repeat  u-pb ng-scope" ng-repeat="car in rc.results.vehicles track by car.registration" style="">
      <div class="o-media  c-card  c-card--hover  c-card__block  u-p-0  u-shadowed  u-shadowed--hover">
        <div class="o-media__left  o-grid__col-sm-5  o-grid__col-xs-12  u-p-0  u-no-float--sm">

          <a ng-href="/used-car/FORD/FIESTA/BJ11TFZ" class="o-embed-responsive  o-embed-responsive--16by9  o-media__object  c-rollover" ng-click="rc.viewCar(car, $index)" href="/used-car/FORD/FIESTA/BJ11TFZ">
            <img ng-src="//images.mycar.com/BJ/11/BJ11TFZ/BJ11TFZ-used-FORD-FIESTA-DIESEL-HATCHBACK-1-6-TDCi-95-Titanium-3dr-Diesel-Manual-RED-2011-HR-S-01.jpg" alt="FORD FIESTA" class="o-embed-responsive__item  c-rollover__image" cs-src-responsive="[ [ 'small', '//images.mycar.com/BJ/11/BJ11TFZ/BJ11TFZ-used-FORD-FIESTA-DIESEL-HATCHBACK-1-6-TDCi-95-Titanium-3dr-Diesel-Manual-RED-2011-HR-M-01.jpg' ], [ 'retina', '//images.mycar.com/BJ/11/BJ11TFZ/BJ11TFZ-used-FORD-FIESTA-DIESEL-HATCHBACK-1-6-TDCi-95-Titanium-3dr-Diesel-Manual-RED-2011-HR-M-01.jpg' ] ]" src="//images.mycar.com/BJ/11/BJ11TFZ/BJ11TFZ-used-FORD-FIESTA-DIESEL-HATCHBACK-1-6-TDCi-95-Titanium-3dr-Diesel-Manual-RED-2011-HR-M-01.jpg">
          </a>
        </div>
        <div class="o-media__body  o-media--middle  c-card">

          <label class="c-option  c-option--stacked  u-pos-t-r  u-text-primary  u-m-sm  u-hidden-print">
            <input checklist-value="car.registration" ng-model="checked" class="ng-scope ng-pristine ng-untouched ng-valid" checklist-model="search.savedVehicles" type="checkbox">
            <i class="c-option__heart"></i>
            <span class="u-text-70">Save</span>
          </label>
          <div class="c-card__block" ng-click="rc.viewCar(car, $index)">
    <strong ng-if="car.vehicleCapDetails.capMakeName != 'MERCEDES-BENZ'" class="ng-binding ng-scope">
              FORD FIESTA
            </strong>
            <div class="u-text-strong  u-text-small ng-binding">1.6 TDCi [95] Titanium 3dr, 2011</div>


    <div class="u-text-bold  u-lh-1  u-pt-sm ng-scope" ng-if="!search.criteria.fromPrice &amp;&amp; !search.criteria.toPrice">
              <small>From</small> <span class="u-text-125 ng-binding">£114</span> <small>monthly or</small>
              <span ng-if="!car.vehiclePrice.exVatPrice" class="ng-binding ng-scope">£5,071</span>

            </div>
            <div class="u-text-70  u-text-muted  u-text-nowrap  u-py-sm"> + £149 Admin Fee</div>
            <ul class="o-list-inline  u-text-70  u-text-muted">
              <li class="o-list-inline__item  u-pl-0  u-pr-sm">
                <span ng-if="car.mileage > 1000" class="ng-binding ng-scope">
                  67k miles
                </span>

              </li>
              <li class="o-list-inline__item  u-pl-0  u-pr-sm ng-binding">
                Diesel
              </li>
              <li class="o-list-inline__item  u-pl-0  u-pr-sm ng-binding">
                Manual
              </li>
              <li class="o-list-inline__item  u-pl-0  u-pr-sm ng-binding">
                Red
              </li>

              <li class="o-list-inline__item  u-pl-0 ng-binding">
                <i class="i-icon  i-icon--location"></i>&nbsp;Norton<span class="u-text-strong ng-binding ng-scope" ng-if="car.distance">, 2mi</span>
              </li>
            </ul>
          </div>
        </div>
      </div>

推荐答案

如果li元素的类名是唯一的,则可以使用:

If the classname of the li element is unique, you can use:

        WebElement resultsLists= driver.findElement(By.id("resultsLists"));
        WebElement el=resultsLists.findElement(By.xpath(".//li[@class='c-animate  c-animate--repeat  u-pb ng-scope']/div/div/a"));
        System.out.println(el.getAttribute("href"));

否则,您可以使用索引来访问元素.如果是第一个:

Otherwise, you can use the index to access to the element. If is the first one:

    WebElement resultsLists= driver.findElement(By.id("resultsLists"));
    WebElement el=resultsLists.findElement(By.xpath(".//li[1]/div/div/a"));
    System.out.println(el.getAttribute("href"));

这篇关于从订单项列表中提取href值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆