browse a website using selenium webdriver

0 votes

Is it possible to go through all the URIs of a given website using Selenium WebDriver?
 

I want to launch a Firefox browser using selenium with a given URL of my choice, and then I want the firefox to browse all the pages that website has using Python language.

Jun 8, 2018 in Selenium by DataKing99
• 8,130 points
38 views

1 answer to this question.

0 votes

You can use the below code:

public class BrowseLink {
  
    static List<String> linkAlreadyVisited = new ArrayList<String>();
    WebDriver driver;

    public RecursiveLinkTest(WebDriver driver) {
        this.driver = driver;
    }

    public void linkTest() {
        for(WebElement link : driver.findElements(By.tagName("a")) {
       
            if (link.isDisplayed() 
                        && !linkAlreadyVisited.contains(link.getText())) {
        
                linkAlreadyVisited.add(link.getText());
                System.out.println(link.getText());
             
                link.click();
                
                new RecursiveLinkTest(driver).linkTest();
            }
        }
        driver.navigate().back();
    }

    public static void main(String[] args) throws InterruptedException {
        WebDriver driver = new FirefoxDriver();
        driver.get("http://newtours.demoaut.com/");
        
        new RecursiveLinkTest(driver).linkTest();
    }
}
answered Jun 8, 2018 by Meci Matt
• 9,420 points

Related Questions In Selenium

0 votes
1 answer

I tried to open a new website when a new tab is opened using Selenium Webdriver

Try this code: ArrayList<String> tabs = new ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,090 points
906 views
0 votes
1 answer

Double click a record in a grid using Selenium webdriver

Try Actions class to perform this Actions action ...READ MORE

answered Mar 29, 2018 in Selenium by Damon Salvatore
• 5,510 points
991 views
0 votes
1 answer

Select an item from a dropdown list using Selenium WebDriver

Use this then it will work - new ...READ MORE

answered Apr 9, 2018 in Selenium by Vardy
• 2,250 points
2,072 views
0 votes
1 answer

30 min Wait on a page and then perform any Operation using Selenium Webdriver

Implicit wait tells webdriver to poll the ...READ MORE

answered Apr 19, 2018 in Selenium by Shubham
• 13,290 points
121 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
592 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
901 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
579 views
0 votes
1 answer
0 votes
1 answer

Is it possible for a website to detect that we are using Selenium with ChromeDriver

Selenium tests for pre-defined javascript variables which ...READ MORE

answered Apr 27, 2018 in Selenium by Meci Matt
• 9,420 points
2,189 views