ui自动化,元素定位,操作,selenium,java--L

  1.  id,name,tagName,className, linktext, partialLinkText, cssSelector, xpath 定位
    *** id 定位元素:
    WebElement input = driver. findElement(By. id("kw"));
    *** 查看元素的其他属性:
    String maxlength = input . getAttribute("maxlength");
    *** //二: name -->名称--》提交到后端的标识
    WebElement input =driver. findElement(By . name( "wd"));
    String maxlength = input. getAttribute(”maxlength" );
    System. out . println(maxlength) ;
    *** //E:tagName --》标签名, -般用得少
    List<WebElement> elements = driver. findElements(By . tagName(" input"));
    System . out . println(elements.size());
    *** //四: className --》 样式名
    WebElement input = driver . findElement(By .className("s_ ipt"));
    String maxlength = input . getAttribute( "maxlength");
    System. out. println(maxlength);
    *** //五: linkText -- >超链接的完整文本
    WebElement aElement = driver . findElement (By. linkText("学术"));
    //点击这个超链接
    aElement.click();
    *** //六: partialLinkText -- >超链接的部分文本(模糊匹配)
    WebElement aElement = driver. findElement(By . partiall inkText(""));
    //点击这个超链接
    aElement .click();|
    *** //七: cssSelector-- >样式选择器
    //语法:标签名[属性名=属性值] [属性名2=属性值2] [属性名3=属性值3]....
    //组合查询、多条件的筛选
    //1)单属性
    WebElement -input = driver . findElement(By . cssSelector(" input [maxlength=='255']"));
    System. out . println( input . getAttribute("class"));
    备注:【“”】里面不能有“”,应该把内部的【“”】换成【''】
    //2)多属性
    WebElement -input = driver . findElement(By . cssSelector(" input [maxlength=='255'][ autocomplete= 'off ' ]"));
    input . sendKeys("中国人");
    *** //八: xpath --》 xm1路径表达式
    //通过工具去找
    WebElement input = driver . findElement(By .xpath("//*[@id=' kw']"));
    input . sendKeys("你好棒");
    *** //火狐: firepath插件
  2.  
  3.  
  4.   
  5.  
  6.  
  7.  
  8.  
  9.  
------------------------这是用来做笔记的,可能不够详细,如有问题可以留言-------------------------
原文地址:https://www.cnblogs.com/focusta/p/12185981.html