如果内部span或锚文本不包含类名,如何访问它们

时间:2015-06-25 20:45:53

标签: webdriver

我想点击Desserts和其他列表项,右键点击它即可

x path : //*[@id="foodMenuPanels"]/div[2]/div/div[1]/ul/li[1]/a/text()

HTML

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 25 March 2009), see www.w3.org" />

  <title></title>
</head>

<body>
  <div id="foodMenuPanels" class="food-menu-wrapper">
    <div class="food-menu-panel food-panel-results">
      <div class="food-menu-content">
        <ul class="food-menu-list"></ul>
      </div>
    </div>

    <div class="food-menu-panel food-panel-categories">
      <div class="food-menu-subpanel-wrapper">
        <!-- food-menu-content food-panel-categories -->

        <div class="food-menu-content food-panel-categories">
          <ul data-id="14386" class="food-menu-list">
            <li class="">
              <a href="/menu/desserts/" data-internal="14349" class="ripple">Desserts</a>

              <div class="ripples"></div>
            </li>

            <li class="">
              <a href="/menu/small-plates-snacks-appetizers/" data-internal="17145"
              class="ripple">Small Plates &amp; Snacks &amp; Appetizers</a>

              <div class="ripples"></div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</body>
</html>

我尝试了几次,但它不起作用,我是硒工具的新手。

1 个答案:

答案 0 :(得分:0)

我会说去css而不是xpath

a[href='/menu/desserts/']

翻译:找到href =“/ menu / desserts /”

的锚标签

第二个锚

a[href$='small-plates-snacks-appetizers/']

翻译:找到href以“small-plates-snacks-appetizers /”

结尾的锚标签