分析:https://github.com/页面Li

 <div class="header header-logged-out">
<div class="container clearfix"> <a class="header-logo-wordmark" href="https://github.com/">Github</a> <ul class="top-nav">
<li class="explore"><a href="https://github.com/explore">Explore GitHub</a></li>
<li class="search"><a href="https://github.com/search">Search</a></li>
<li class="features"><a href="https://github.com/features">Features</a></li>
<li class="blog"><a href="https://github.com/blog">Blog</a></li>
</ul> <div class="header-actions">
<a class="button primary" href="https://github.com/signup">Sign up for free</a>
<a class="button" href="https://github.com/login">Sign in</a>
</div> </div>
 WebElement element1 = webdriver.findElement(By.id("header"));
WebElement element2 = webdriver.findElement(By.name("name"));
WebElement element3 = webdriver.findElement(By.tagName("a"));
WebElement element4 = webdriver.findElement(By.xpath("//a[@title='logo']"));
WebElement element5 = webdriver.findElement(By.cssSelector(".feautures"));
WebElement element6 = webdriver.findElement(By.linkText("Blog"));
WebElement element7 = webdriver.findElement(By.partialLinkText("Ruby"));
WebElement element8 = webdriver.findElement(By.className("login"));
List<WebElement> webElements = webdriver.findElements(By
.xpath("//ul[@class='nav logged_out']/li"));

13使用 CSS 选择器 (By.cssSelector()) 来检索LI标记。

List<WebElement> webElements = webdriver.findElements(By
.cssSelector("ul.nav li"));

可在所检索的项数量上生成断言,如 清单 14所示。

Assert.assertEquals(5, webElements.size());

前面的步骤验证了LI标记数量等于 5。

下一步是检索每个LI标记中的每个锚点(A标记)。

展示了如何在第一个LI中获取锚点。此用例使用了 tagName (By.tagName()) 策略。

WebElement anchor1 = webElements.get(0).findElement(By.tagName("a"));

您可以使用类似的方法收集到所有的 5 个锚点,如 清单 16所示。

WebElement anchor1 = webElements.get(0).findElement(By.tagName("a"));
WebElement anchor2 = webElements.get(1).findElement(By.tagName("a"));
WebElement anchor3 = webElements.get(2).findElement(By.tagName("a"));
WebElement anchor4 = webElements.get(3).findElement(By.tagName("a"));
WebElement anchor5 = webElements.get(4).findElement(By.tagName("a"));

在这一阶段,您可以验证,锚点内的文本是否与所期望的字符串一致。要检索标记内的文本,WebDriver 提供了getText()方法。清单 展示了完整的测试方法,以及测试底部的断言。

Assert.assertEquals("Signup and Pricing", anchor1.getText()); A

ssert.assertEquals("Explore GitHub", anchor2.getText());

Assert.assertEquals("Features", anchor3.getText());

Assert.assertEquals("Blog", anchor4.getText());

Assert.assertEquals("Login", anchor5.getText());

Selenium html之于ul标志代码分析与使用的更多相关文章

  1. 完整全面的Java资源库(包括构建、操作、代码分析、编译器、数据库、社区等等)

    构建 这里搜集了用来构建应用程序的工具. Apache Maven:Maven使用声明进行构建并进行依赖管理,偏向于使用约定而不是配置进行构建.Maven优于Apache Ant.后者采用了一种过程化 ...

  2. 集成TFS Build生成与SonarQube获取代码分析结果

    软件项目在开发过程中,往往由于任务重.时间紧等原因忽略软件代码的质量和规范检查,只注重软件功能的开发和交付.等软件交付上线以后,由于代码质量导致的问题会耗费开发和运维人员的大量时间.研发表明,项目上线 ...

  3. DWM1000 测距原理简单分析 之 SS-TWR代码分析2 -- [蓝点无限]

    蓝点DWM1000 模块已经打样测试完毕,有兴趣的可以申请购买了,更多信息参见 蓝点论坛 正文: 首先将SS 原理介绍中的图片拿过来,将图片印在脑海里. 对于DeviceA 和 DeviceB来说,初 ...

  4. verilog 代码分析与仿真

    verilog 代码分析与仿真 注意:使用vivado 自带的仿真工具, reg和wire等信号需要赋予初始值 边沿检测 module signal_test( input wire cmos_pcl ...

  5. 2018-2019 2 20165203 《网络对抗技术》 Exp4 恶意代码分析

    2018-2019 2 20165203 <网络对抗技术> Exp4 恶意代码分析 实验要求 监控你自己系统的运行状态,看有没有可疑的程序在运行. 分析一个恶意软件,就分析Exp2或Exp ...

  6. JS日期级联组件代码分析及demo

    最近研究下JS日期级联效果 感觉还不错,然后看了下kissy也正好有这么一个组件,也看了下源码,写的还不错,通过google最早是在2011年 淘宝的虎牙(花名)用原审JS写了一个(貌似据说是从YUI ...

  7. 2018-2019-2 20165330《网络对抗技术》Exp4 恶意代码分析

    目录 基础问题 相关知识 实验目的 实验内容 实验步骤 实验过程中遇到的问题 实验总结与体会 实验目的 监控你自己系统的运行状态,看有没有可疑的程序在运行 分析一个恶意软件,就分析Exp2或Exp3中 ...

  8. OVS 内核KEY值提取及匹配流表代码分析

    原文链接:http://ry0117.com/2016/12/24/OVS内核KEY值提取及匹配流表代码分析/ 当开启OVS后,创建datapath类型为system的网桥并他添加相关接口,OVS网桥 ...

  9. Https与Http,SSL,DevOps, 静态代码分析工具,RFID, SSH, 非对称加密算法(使用最广泛的一种是RSA), 数字签名, 数字证书

    在URL前加https://前缀表明是用SSL加密的. 你的电脑与服务器之间收发的信息传输将更加安全. Web服务器启用SSL需要获得一个服务器证书并将该证书与要使用SSL的服务器绑定. http和h ...

随机推荐

  1. UDP广播问题

    http://bbs.csdn.net/topics/390218123 Broadcast Address(广播地址)是专门用于同时向网络中所有工作站进行发送的一个地址.在使用TCP/IP 协议的网 ...

  2. poj 3264 Balanced Lineup(RMQ裸题)

    Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 43168   Accepted: 20276 ...

  3. class str

    class str(object): """ str(object='') -> str str(bytes_or_buffer[, encoding[, erro ...

  4. HDU2553N皇后问题(状态压缩)

    这道题其实最简单的方法就是打表,直接DFS会超时,那就先运行一遍,找出1~10的值,打表即可,这里提供DFS和打表的数据 DFS:(白书上的)TLE #include <stdio.h> ...

  5. class DelegatingFilterProxy

    /** * Proxy for a standard Servlet Filter, delegating to a Spring-managed bean that * implements the ...

  6. hdu-4753-Fishhead’s Little Game-记忆化搜索

    网赛的一道题目,当时没做出来. 由题意可知,最多只有12条边未知. 所以最多只有(1<<12)种状态. 所以记忆化搜索这种状态下,枚举添加任意一条边之后的状态的最优值. #include& ...

  7. OC:copy 与 retain 的区别

    copy与retain的区别: copy是创建一个新对象,retain是创建一个指针,引用对象计数加1.Copy属性表示两个对象内容相同,新的对象retain为1 ,与旧有对象的引用计数无关,旧有对象 ...

  8. C#获取程序集的版本号和最后编译时间

    C#获取程序集的版本号:string ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToStrin ...

  9. 应用程序如何找到DLL文件?

    使用LoadLibrary显式链接,那么在函数的参数中可以指定DLL文件的完整路径: 如果不指定路径,或者进行隐式链接,Windows将遵循下面的搜索顺序来定位DLL: (1)包含EXE文件的目录(2 ...

  10. Ember学习(8):REOPENING CLASSES AND INSTANCES

    英文原址:http://emberjs.com/guides/object-model/reopening-classes-and-instances/ 你不须要一次就完毕类所有内容的定义,通过reo ...