How to find broken links in web application using Selenium | Pradeep Nailwal
Вставка
- Опубліковано 15 вер 2024
- package com.org.selenium;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class BrokenHyperlinks {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "E:\\Drivers\\Chrome109\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("localhost:8080/AdhisaClassesWebApplication/");
HttpURLConnection huc = null;
List allHyperlinksList = driver.findElements(By.tagName("a"));
for (Object hyperLink : allHyperlinksList) {
String url = ((WebElement)hyperLink).getAttribute("href");
try {
URL actualUrl = new URL(url);
huc = (HttpURLConnection) actualUrl.openConnection();
huc.setRequestMethod("HEAD");
huc.connect();
int respCode = huc.getResponseCode();
if (respCode == 400) {
System.out.println(url + " is a BROKEN link");
} else {
System.out.println(url + " is a VALID link");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
--------------------------------------------------------------------------------------------------------------------------------
#java#restassured #soapui #postman #extentreport #selenium #jmeter #api #testing #training #refermegroup #jenkins #maven #github #apitesting #cicd #agiletesting #cucumber #sonar #robotframework #Error #Defect #Bug #Failure #api #webdesigner #webdriver #web #java #html #html5 #performance #manualtesting #junit #mutable #immutable #singleton #casting #synchronization #jmeter
Refer my channel for Manual Testing concepts also like #Error, #Defect, #Bug and #Failure
Very well explained sir . Thank you so much 😊
Thanks for Motivation 🙂👍
Useful Video looking for more such video :)
Thanks for Motivation 🙂
Nice explained Sir 👍
Thanks for Motivation 🙂
Excellent video
Thanks for Motivation and keep watching other videos 🙂
What is meaning HEAD ?
Sir can you please provide the hyperlink page
ok, ping me on whatsapp