How To Get/Extract All Links From Web Page Using Selenium WebDriver

As nosotros all knows, Each as well as every software spider web application contains many issue of unlike links/URLs. Some of them are redirecting to unopen to page of same website as well as others are redirecting to whatsoever external software spider web application. One of my spider web log reader has requested the webdriver software test script instance for extracting all these links from page as well as impress it inwards console using selenium webdriver. I convey created as well as published many different WEBDRIVER EXAMPLE SCRIPTS on this spider web log but requested instance past times spider web log reader is non pushed till right away as well as hence I convey created instance for the same to part amongst all of you.

You tin await at instance of EXTRACTING TABLE DATA USING SELENIUM WEBDRIVER.

We convey seen HOW TO USE findElements inwards webdriver to locate multiple elements of software spider web page. We tin purpose same affair hither to locate multiple links of the page. Bellow given instance volition recollect all URLs from the software spider web page as well as volition impress all of them inwards console. You tin click on each URL if yous wishing to create so. Try bellow given instance for unlike websites past times providing that website's URL in @Before annotation.

Copy bellow given @Test method business office of extract all links from software spider web page and supersede it amongst the @Test method business office of instance given on THIS PAGE.(Note : @Test method is marked with pink color in that linked page).

@Test   populace void essay () throws InterruptedException    {   endeavor {     List<WebElement> no = driver.findElements(By.tagName("a"));     int nooflinks = no.size();      System.out.println(nooflinks);     for (WebElement pagelink : no)          {           String linktext = pagelink.getText();           String link = pagelink.getAttribute("href");            System.out.println(linktext+" ->");           System.out.println(link);           }    }catch (Exception e){              System.out.println("error "+e);          }               }

THIS LINK volition demonstrate yous many other basic activity ascendency examples. Have yous READ POST on how to uncovering broken link from page?

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post