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

  

Selenium webdriver 获取属性值 元素里的value的更多相关文章

  1. java 反射机制--根据属性名获取属性值

    1.考虑安全访问范围内的属性,没有权限访问到的属性不读取 /** * 根据属性名获取属性值 * * @param fieldName * @param object * @return */ priv ...

  2. storm源码之巧用java反射反序列化clojure的defrecord获取属性值

    [原创]storm源码之巧用java反射反序列化clojure的defrecord获取属性值 [原创]storm源码之巧用java反射反序列化clojure的defrecord获取属性值 storm源 ...

  3. C# 反射获取属性值、名称、类型以及集合的属性值、类型名称

    实体类 class Product { public string Id { get; set; } public string Name { get; set; } public List<P ...

  4. Python+selenium之获取文本值和下拉框选择数据

    Python+selenium之获取文本值和下拉框选择数据 一.结合实例进行描述 1. 实例如下所示: #新增标签操作 def func_labels(self): self.driver.find_ ...

  5. HtmlAgilityPack中使用xpath获取属性值

    HtmlAgilityPack介绍 HtmlAgilityPack是一个专门用来解析Html的库,它可以使用xml的方式来解析html. 有人说了,html本身不就是xml?是的,html就是xml, ...

  6. Selenium Webdriver——操作隐藏的元素(二)display属性

    有时候我们会碰到一些元素不可见,这个时候selenium就无法对这些元素进行操作了.例如,下面的情况: 页面主要通过“display:none”来控制整个下拉框不可见.这个时候如果直接操作这个下拉框, ...

  7. Selenium Webdriver——操作隐藏的元素display属性

    有时候我们会碰到一些元素不可见,这个时候selenium就无法对这些元素进行操作了.例如,下面的情况: 页面主要通过“display:none”来控制整个下拉框不可见.这个时候如果直接操作这个下拉框, ...

  8. selenium又一小坑 无法用XPATH直接获取属性值 需要使用.get_attribute(“href”)

    在使用selenium进行抓取url的时候,试图使用find_elements_by_xpath来获取. 因此想当然的直接使用XPATH的语法进行获取属性 事例缩略后xml结构如下 <div c ...

  9. H5_0017:通过元素自定义属性值获取元素对象,并获取属性值

            // 通过元素的属性值查找对象         // document.querySelectorAll("[data]").forEach(function(e) ...

随机推荐

  1. 用Visual C#来清空回收站(2)

    四.程序的源代码(recycled.cs).编译方法及运行后的界面: (1).程序的源代码:recycled.cs: using System.IO ; using System.Windows.Fo ...

  2. R 分组计算描述性统计量

    统计学区内各个小区的房价均值 数据格式 id|community_name|house_area|house_structure|house_total|house_avg|agency_name|h ...

  3. window下配置Apache2服务器

    1:去Apache.org下载安装包 http://httpd.apache.org/ 2:解压到某一个目录 3:修改httpd.conf(Apache的解压目录和端口号) 4:管理员方式启动cmd执 ...

  4. idea缓存目录mac cache

    IDEA如果出现卡顿,Index疯狂扫描,建议清空一下如下目录 ~/Library/Caches/IntelliJIdea2017.3 Resource nexus-maven-repository- ...

  5. 在Android Studio中打开Android Device Monitor时报错的解决方法

    在Android Studio中打开Android Device Monitor时报以下错误时(Android-SDK\tools\lib\monitor-x86_64\configuration\1 ...

  6. linux安装experss搭建本地服务器

    准备nodejs和npm 保证本地安装了nodeJS和npm,如果没有安装的话,通过下面的命令进行安装: sudo apt-get install nodejs //安装nodeJS sudo apt ...

  7. Excel 2007 若干技巧。

    1.自定义序列 office按钮→excel选项→常用→编辑自定义列表 2.无法清空剪贴板错误的处理办法: 取消"显示粘贴选项"选项 3.每次选定同一单元格 输入后按ctrl+En ...

  8. TQ2440与西门子S7-200 PLC自由口通信实现过程中问题总结

    1.在win7上安装好PLC编程软件 STEP 7 MicroWIN 之后,无法实现编程软件与PLC的通信连接? 原因:STEP 7 MicroWIN 对win7支持不是很好 解决办法:在win7中安 ...

  9. HttpLuaModule——翻译(Nginx API for Lua)

    现在我已经将翻译的内容放到:http://wiki.nginx.org/HttpLuaModuleZh Nginx API for Lua Introduction 各种各样的*_by_lua和*_b ...

  10. 用python解析pdf中的文本与表格【pdfplumber的安装与使用】

    我们接触到的很多文档资料都是以pdf格式存在的,比如:论文,技术文档,标准文件,书籍等.pdf格式使得用机器从中提取信息格外困难. 为了解决这个问题,我找到了几种解决方案,最后选择了python上的p ...