zoukankan      html  css  js  c++  java
  • selenium之xpath /css

    xpath:

    a'a   @title="a'a

    //a[contains(text(),'product_08')]/ancestor::tr//input[@class='live-tv-overview-delete']

    WebElement delConfirmBut = driver.findElement(By.xpath("//div[starts-with(@id,'confirmDialog')]/div/div/div[3]/button[1]"));
    delConfirmBut.click();

    Actions action = new Actions(driver);
    action.moveByOffset(4, 5).click();

    1.last()-n position()<n
    2.contains,startwith,endwith and or
    3. /B[1] [Last()]第一个B的子元素
    4. //@*  任意属
     
    form/element[last()]
    form/element[last()-n] 选择倒数第几个
    form/element[position()<n]位置小于n的element
    form/element[@attr_name>Number] form节点下所有带attr_name属性,且属性值大于number的element
    form/element[@attr_name<Number]
    path1|path2  匹配1和2
    //form/a[contains(text(),'text')]
    xpath=//tbody[starts-with(@id,'normalthread_')]//td[@class='by'][1]//em//span[contains(@title,'${today}')][1]/parent::tr 
     
    WebElement hello = driver.findElement(By.id("div1")).findElement(By.lindText("hello"));
    =driver.findElement(By.tagName("").tagName(""));
     
     
    (By.xpath("//em[ @testid='123'   and/or   @id='button_delete' ]")).click();
    (By.xpath("//em[ @testid='123'   and contains(text(),'nash') ]"))
    ( B y. x p a t h ("//input[@type='submit'][@value='Login']")); 
    (B y .x p a t h ("img[@alt]")); 
    wd.findElement(By.xpath("//a[text()='商户管理']")).click();
     
     //div[contains(@id,'mzLoginArea4')]
    (B y .x p a t h( " / / t d [c o n t ai n s ( te x t ( ), ' N a sh ' )]
    //div[a[@id= 'mzLogin']]
     
     

    driver.findElement(By.xpath("//a[contains(text(),'aaa')]"));

    driver.findElement(By.xpath("//a[text()='aaa']"));

    driver.findElement(By.xpath(".//*[@id='buy_count']/../a[contains(.,'+')]"));

                       <input id="buy_count" type="text" disabled="disabled" readonly="readonly" value="1">

              <a class="plus_proinfo" href="javascript:;">+</a>

                      

    driver.findElement(By.xpath("//a[contains(@id,'aaa')][1]"));

    driver.findElement(By.xpath("//a[@id='123'][@value='sadcds']"));

                       //body[form]     body/a

                      

    driver.findElement(By.xpath("//a[starts-with(@id,'aaa_')]"));

    driver.findElement(By.xpath("//a[starts-with(@id,'aaa_') and contains(text(),'sds')]"));

    driver.findElement(By.xpath("//a[ends-with(@id,'aaa_') or contains(text(),'sds')]"));

                      

    driver.findElement(By.xpath("//a/div[Last()-1]"));

    driver.findElement(By.xpath("//a/div[@classnum<5]"));

                      

    driver.findElement(By.tagName("a").id("cdcd"));

    driver.findElement(By.tagName("a")).findElement(By.id("sd"));

                      

    如果要继续找子节点呢?we.findElement(By.xpath("//p"),但是,这样写是不对的,其结果是找到全部p标签,正确的写法是  we.findElement(By.xpath(".//p"),表示当前WebElement下的p标签。

    Css:

     
    1.driver.findElement(By.cssSelector("#username"));  
    2.driver.findElement(By.cssSelector("标签名[属性名='属性值']"));  
    3.
    ^=  driver.findElement(By.cssSelector("标签名[属性名^='xxx']"));  匹配属性值以xxx开头的元素
    $=  driver.findElement(By.cssSelector("标签名[属性名$='xxx']"));  匹配属性值以xxx结尾的元素  
    *=  driver.findElement(By.cssSelector("标签名[属性名^='xxx']"));  匹配属性值包含xxx的元素 

  • 相关阅读:
    Hbase 性能改进
    HBase总结(十一)hbase Java API 介绍及使用示例
    Java中如何遍历Map对象的4种方法
    Jsp分页实例---假分页
    Jsp分页实例---真分页
    Java正则表达式
    平均时间复杂度为O(nlogn)的排序算法
    常见排序算法--简单排序
    [kuangbin带你飞]专题一 简单搜索
    [kuangbin带你飞]专题一 简单搜索
  • 原文地址:https://www.cnblogs.com/season-xie/p/5330813.html
Copyright © 2011-2022 走看看