zoukankan      html  css  js  c++  java
  • Selenium webdriver 获取属性值 元素里的value

    1.WebElement webElemt= webElement.findElement(By.xpath("//*[@class='xxxxxx]/a"));
    //在ie下使用innerText 在火狐下使用textContent
    String linktext = webElemt.getAttribute("innerText");
    
    
    2.WebElement element = ...;//测试的好像不行。
    
     ((JavascriptExecutor) driver).executeScript("return arguments[0].getText();", element);
    
          

    Example:

    <div class="userinfobox2 clearfix">
    <p class="userrankbox1 pull-left"><strong>233</strong>
    <span>
    <a href="javascript:void(0)">发送数</a>
    </span>
    </p>
    <p class="userrankbox1 pull-left"><strong>97</strong><span>
    <a href="javascript:void(0)">收到数</a>
    </span></p>
    </div>

    		1.1 WebElement findElement = driver.findElement(By.xpath("//div[@class='userinfobox2 clearfix']//strong[1]"));
    		System.out.println("findelement:" + findElement.getText()); //233
             1.2 WebElement findElement2 = driver.findElement(By.xpath("//div[@class='userinfobox2 clearfix']//strong[last()]"));
    		System.out.println("findElement2:" + findElement2.getAttribute("innerText")); //233       
    		1.3 WebElement findElement4 = river.findElement(By.xpath("//p[@class='userrankbox1 pull-left'][1]/strong"));
    		System.out.println("findElement4:"+findElement4.getText()); //233
           	1.4 WebElement findElement5 = driver.findElement(By.xpath("//p[@class='userrankbox1 pull-left'][2]/strong"));
    		System.err.println("findElement5:"+findElement5.getText());//97
    

      

  • 相关阅读:
    565. Array Nesting
    796. Rotate String
    817. Linked List Components
    696. Count Binary Substrings
    SQL语句优化
    java7增强的try语句关闭资源
    java新手自己实现的计算器,有点乱
    java数组
    java创建不存在路径的文件
    class.forName
  • 原文地址:https://www.cnblogs.com/amosli/p/3415856.html
Copyright © 2011-2022 走看看