H
H
Hayk212021-09-13 13:28:03
selenium
Hayk21, 2021-09-13 13:28:03

How to understand that all links in the footer work?

How to understand that all links in the footer work?

how to check all working links in this footer? Java/Selenium

613f261b19687168829690.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan Hasanli, 2021-09-13
@Hayk21

You can get the HTTP status of these links.
Here is a simple example (the code below can be shortened and simplified):

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class URLChecker {

  public static int checkUrl(String currentUrl) {
    URL checkUrl = null;
    HttpURLConnection http = null;
    int statusCode = 0;
    try {
      checkUrl = new URL(currentUrl);
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }
    try {
      if (checkUrl != null) {
        http = (HttpURLConnection)checkUrl.openConnection();
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    try {
      if (http != null) {
        statusCode = http.getResponseCode();
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    return statusCode;
  }
}

And then you check the status of the link and if it is 200, then everything is OK. If not, then the link is not working.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question