analysis : page Li

 <div class="header header-logged-out">
<div class="container clearfix"> <a class="header-logo-wordmark" href="">Github</a> <ul class="top-nav">
<li class="explore"><a href="">Explore GitHub</a></li>
<li class="search"><a href="">Search</a></li>
<li class="features"><a href="">Features</a></li>
<li class="blog"><a href="">Blog</a></li>
</ul> <div class="header-actions">
<a class="button primary" href="">Sign up for free</a>
<a class="button" href="">Sign in</a>
</div> </div>
 WebElement element1 = webdriver.findElement("header"));
WebElement element2 = webdriver.findElement("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 Use CSS Selectors (By.cssSelector()) To search LI Mark .

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

Assertions can be generated on the number of items retrieved , Such as detailed list 14 Shown .

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

The previous steps verify LI The number of tags equals 5.

The next step is to retrieve each LI Each anchor in the tag (A Mark ).

It shows how in the first LI Get anchor points in . This use case uses tagName (By.tagName()) Strategy .

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

You can use a similar method to collect all 5 An anchor , Such as detailed list 16 Shown .

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"));

At this stage , You can verify , Whether the text in the anchor matches the expected string . To retrieve the text within the tag ,WebDriver Provides getText() Method . detailed list Shows the complete test method , And the assertion at the bottom of the test .

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 To ul Logo code analysis and use of more related articles

  1. Complete and comprehensive Java The repository ( Include build 、 operation 、 The code analysis 、 compiler 、 database 、 Community, etc )

    structure Here's a collection of tools for building applications . Apache Maven:Maven Build with declarations and manage dependencies , Prefer to build with conventions rather than configurations .Maven be better than Apache Ant. The latter uses a process ...

  2. Integrate TFS Build Generation and SonarQube Get code analysis results

    Software projects in the development process , Often because of the heavy task . Time constraints and other reasons ignore the quality of software code and specification check , Focus only on the development and delivery of software functions . After the software is delivered online , Problems caused by code quality will cost developers and operators a lot of time . R & D shows that , Project online ...

  3. DWM1000 The principle of ranging is simple And SS-TWR The code analysis 2 -- [ The blue dot is infinite ]

    Blue dot DWM1000 The module has been proofed and tested , Interested can apply to buy , For more information, see   Blue dot Forum Text : First of all, will SS Here are the pictures in the principle introduction , Print the picture in your mind . about DeviceA and DeviceB Come on , first ...

  4. verilog Code analysis and simulation

    verilog Code analysis and simulation Be careful : Use vivado Built in simulation tools , reg and wire We need to give the initial value to the equal signal Edge detection module signal_test( input wire cmos_pcl ...

  5. 2018-2019 2 20165203 《 Network countermeasure technology 》 Exp4 Malware Analysis

    2018-2019 2 20165203 < Network countermeasure technology > Exp4 Malware Analysis The experimental requirements Monitor the operation of your own system , See if there are suspicious programs running . Analyze a malware , Just analyze Exp2 or Exp ...

  6. JS Date cascade component code analysis and demo

    Recent research JS Date cascade effect It feels good , Then I took a look kissy There is just such a component , Also looked at the source code , It's not bad , adopt google The first is in the 2011 year Taobao's tiger teeth ( flower ) Using the original trial JS Wrote a ( It seems that it is said that it came from YUI ...

  7. 2018-2019-2 20165330《 Network countermeasure technology 》Exp4 Malware Analysis

    Catalog Basic questions Related knowledge The experiment purpose Experimental content The experimental steps Problems encountered during the experiment Experiment summary and experience The experiment purpose Monitor the operation of your own system , See if there are suspicious programs running Analyze a malware , Just analyze Exp2 or Exp3 in ...

  8. OVS kernel KEY Value extraction and matching flow table code analysis

    Link to the original text : kernel KEY Value extraction and matching flow table code analysis / When open OVS after , establish datapath The type is system And he added related interfaces ,OVS bridge ...

  9. Https And Http,SSL,DevOps, Static code analysis tool ,RFID, SSH, Asymmetric encryption algorithm ( The most widely used one is RSA), digital signature , digital certificate

    stay URL Before to add https:// The prefix indicates the use of SSL Encrypted . The information transmission between your computer and the server will be more secure . Web Server enable SSL You need to get a server certificate and use it with SSL Server binding for . http and h ...

Random recommendation

  1. iOS- Return block The road of Xiaobai

    In my first contact with iOS When developing , It's through MJ The teacher speak OC Basic introduction ,iOS Everyone in the circle should know MJ Big God , Even so, God , That's all block I still feel dizzy after that , Until later, I really went into the company to do projects , I still feel like I am ...

  2. aggregate Collection

    /* * The origin of the assembly : * We're learning object-oriented languages , The object-oriented language describes things through objects , To facilitate the operation of multiple objects , We have to store these multiple objects . * To store multiple objects , It can't be a basic ...

  3. Python: generator

    generator : Used yield The function of the is called the generator (generator). It remembers where it was in the body of the function the last time it was returned . yeild Operation process : When you ask the generator for a number , The generator will execute , Until  yield  sentence , generator ...

  4. MCS51 Series MCU practical technology part courseware

  5. Network flow - Maximum flow Templates (poj 1273)

    #include<cstdio> #include<iostream> #include<cstring> #include<queue> #defin ...

  6. log4j Abnormal problems

    log4j:WARN No appenders could be found for logger   from : Favourite NBA Write directly about my solution : stay src Next new file be known as log4j.propertie ...

  7. jquery in $(this) Usage of

    When it comes to loops table when , Check it out Properties and values can be a bit of a hassle . You have to use $(this) To solve this kind of problem . 1. Use it directly 2. Use indirectly <table> <?php for ...

  8. Gecko book 8 Dimensionality Reduction

    many Machine Learning problems involve thousands or even millions of features for each training inst ...

  9. iOS - Gaode map's pedestrian route is planned to be multi-point and multi route

    Problems encountered in the project integration of Gaode map : The official pedestrian navigation of Gaud map is only for a single starting point and a single route , Driving navigation is the only way to get there . Now the project is to navigate multiple points and routes on foot

  10. gitlab Check out the project ID/projectId

    background There's a recent CI Packaging platform , project projectId mistake , Cause pull to wrong warehouse . The author has been through the project name (project name) visit , For the first time contact project id, Search around to find a quick way to view , Record here . ...