(Java) Selenium Webdriver Learning---to enable simple page flipping, to remove the title and title links of the content

Source: Internet
Author: User
Tags gettext appium



Selenium Webdriver Learning---to achieve a simple page, the title of the content and the title link out;



This condition is suitable to be able to cycle page=1~n, and each page can be opened with the loop,



Note must be their own splicing URL can be opened, such as: http://ask.testfan.cn/articles?page=15, you can turn to the 15th page of the article classification;


ImportJava.io.File;Importjava.io.IOException;Importjava.util.ArrayList;Importjava.util.List;ImportJava.util.Set;ImportJava.util.concurrent.TimeUnit;Importorg.apache.commons.io.FileUtils;ImportOrg.jsoup.Jsoup;Importorg.jsoup.nodes.Document;Importorg.jsoup.nodes.Element;Importorg.jsoup.select.Elements;ImportOrg.omg.CORBA.PUBLIC_MEMBER;Importorg.openqa.selenium.By;ImportOrg.openqa.selenium.OutputType;ImportOrg.openqa.selenium.TakesScreenshot;ImportOrg.openqa.selenium.WebDriver;Importorg.openqa.selenium.WebElement;ImportOrg.openqa.selenium.chrome.ChromeDriver;ImportOrg.openqa.selenium.phantomjs.PhantomJSDriver;Importorg.openqa.selenium.support.ui.ExpectedCondition;Importorg.openqa.selenium.support.ui.ExpectedConditions;Importorg.openqa.selenium.support.ui.Wait;Importorg.openqa.selenium.support.ui.WebDriverWait; Public classysftest_20180727{Private Static Final intexpectedcondition = 0; Private Static Final intBoolean = 0;  Public Static voidMain (string[] args)throwsinterruptedexception, ioexception{webelement search=NULL; System.setproperty ("Webdriver.chrome.driver", "C:/Program Files (x86)/google/chrome/application/chromedriver.exe"); Webdriver Driver=NewChromedriver (); intPagenum = 15; intI =1;  while(I <=pagenum) {Driver.get ("Http://ask.testfan.cn/articles?page=" +i); //window Maximizationdriver.manage (). window (). Maximize (); //remove the A tag from the titlelist<webelement> ll = driver.findelements (By.cssselector (". Title > A")); //Loop a label  for(webelement w:ll) {//Remove the text corresponding to the A labelSystem.out.println (W.gettext ()); //Remove the element value URL of the href under the a tagSystem.out.println (W.getattribute ("href")); } System.out.println ("section" +i+ "page Crawl Complete"); I= i + 1; } System.out.println ("All crawl Complete");    Driver.close (); } }


The example captures the Testfan software test Community's article title and link (only 15 pages), and the results take the first page as an example:



****************


"Tools to share" jmeter large file analysis tool, 30 times times faster than the official analysis tools
http://ask.testfan.cn/article/1275

http://ask.testfan.cn/article/1223
TESTFAN3 Monthly Interface Free benefit course--seconds kill instructions
http://ask.testfan.cn/article/1201
Python coverage
http://ask.testfan.cn/article/1193
2018 Vocational test must read list
http://ask.testfan.cn/article/1191
selenium--get rid of chrome is being controlled by automated software testing (Java)
http://ask.testfan.cn/article/1187
"Original" appium-desktop version configuration command line run service (MAC)
http://ask.testfan.cn/article/1186
"Original" appium-desktop version configuration command line run service (Windows)
http://ask.testfan.cn/article/1185
Macaca environment configuration and sample execution
http://ask.testfan.cn/article/1181
Selenium Environment Summary
http://ask.testfan.cn/article/1173
Appium Hybrid Hybrid Application test--native switching WebView
http://ask.testfan.cn/article/1169
"Android" To view the app under test package and launchable-activity
http://ask.testfan.cn/article/1168
Quick position Appium Sliding coordinates
http://ask.testfan.cn/article/1158
Design method of test case
http://ask.testfan.cn/article/1157
Common commands for test work
http://ask.testfan.cn/article/1153
Jekins Installation Documentation
http://ask.testfan.cn/article/1152
QTP Frequently Asked questions (Baidu collation)
http://ask.testfan.cn/article/1151
Testfan10 Month Outdoor Climbing activity Registration
http://ask.testfan.cn/article/1150
App Testing Basic Process
http://ask.testfan.cn/article/1149
Software Test Surface questions: Application of software testing tools
http://ask.testfan.cn/article/1148
1th Page Crawl Complete


******************



In this case, the window is maximized: Driver.manage (). Windows (). Maximize ();



Remove the A tag from the title and place it in the list:
list<webelement> ll = driver.findelements (By.cssselector (". Title > A"));



Remove the text corresponding to the A tag:w.gettext ();



Remove the element value URL of the href under the A tag: W.getattribute ("href");






(Java) Selenium Webdriver Learning---to enable simple page flipping, to remove the title and title links of the content


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.