zoukankan      html  css  js  c++  java
  • xpath的定位方式

    <div id="cnblogs_post_body" class="blogpost-body"><p>1.xpath较复杂的定位方法:</p>

    a. 用contains关键字,定位代码如下:

    driver.findElement(By.xpath(“//a[contains(@class, ‘blogpost’)]”));

    <a target="_blank" href="https://www.baidu.com/link?url=imd349" class="c-showurl" style="text-decoration:none;">https://博客.csdn.net/duff2016...&nbsp;</a>、

    b. 用start-with,定位代码如下:

    driver.findElement(By.xpath(“//a[starts-with(@href, ‘https://www.ba’)]));

    c. 用Text关键字,定位代码如下:

    driver.findElement(By.xpath(“//a[contains(text(), ’博客’)]));

    a.starts-with      例子: input[starts-with(@id,'ctrl')]              解析:匹配以 ctrl开始的属性值

    b.ends-with        例子:input[ends-with(@id,'_userName')]     解析:匹配以 userName 结尾的属性值

    c.contains()        例子:Input[contains(@id,'userName')]         解析:匹配含有 userName 属性值

    By.xpath("//input[@type='name' and @name='kw1']")




  • 相关阅读:
    List sort()方法
    解析器
    beautifulsoup库
    break 语句
    enumerate函数
    POJ 1915 Knight Moves
    POJ 1745 Divisibility
    POJ 1731 Orders
    POJ 1664 放苹果
    POJ 1606 Jugs
  • 原文地址:https://www.cnblogs.com/ht22ht22/p/9672660.html
Copyright © 2011-2022 走看看