如何获取无序列表和跨度的xpath

时间:2015-10-09 07:10:32

标签: html css xpath selenium-webdriver

我希望xpath从网页中选择座位“12A”,其中包含要选择的座位列表,其源代码如下:

<div class="seats" style="top: 48px;">
  <ul class="row_12 leftOfAisle">
    <li><a class="" data-row="12" data-seat="A" data-code="SPST" data-amount="300.00" href="javascript:;">
      <span>12A</span></a></li>
    <li><a class="" data-row="12" data-seat="B" data-code="SPST" data-amount="300.00" href="javascript:;">
      <span>12B</span></a></li>
    <li><a class="" data-row="12" data-seat="C" data-code="SPST" data-amount="300.00" href="javascript:;">
      <span>12C</span></a></li>
  </ul>
</div>

我尝试过很多选项而且没有用。我以这个xpath结束了:

"//*[@class='seats']/ul[@class='row_12 leftOf`Aisle']/li[1]/a"

1 个答案:

答案 0 :(得分:0)

在Xpath下面使用

//div[@class='seats']/ul[@class='row_12 leftOfAisle']//span[contains(.,'12A')]

以下是相同的代码: -

List<WebElement> allprice = driver.findElements(By.xpath("//div[@class='seats']/ul[@class='row_12 leftOfAisle']//span"));
for(WebElement price: allprice){

        System.out.println(price.getText());
        price.click() //If you want to click them one by one

}