'How to skip a not working website in eclipse

I have a CSV file with IPs and passwords for cameras. I made a script to go into the website and configure some settings. but the problem is some of these IPs are not working so the page will return 404 not found.

I want to detect these and ignore them, because every time I face a broken page, the for loop stops.

this a portion of my code:

String PathofPage = "http://"+p1+"/doc/page/config.asp";
            
        driver.get(PathofPage);
        driver.manage().window().maximize();
        if( driver.getTitle()=="HTTP 404 Not Found")
            driver.quit();
            WebElement Username = driver.findElement(By.id("username"));
            Username.click(); 

It's not exiting the browser when it finds the title.

This is an example of it's not finding the website

Click Here



Solution 1:[1]

You can optimize the code block to invoke driver.quit() probing if the title contains the expected string inducing WebDriverWait for the titleContains() and you can use the following locator strategy:

try {
    new WebDriverWait(driver, 20).until(ExpectedConditions.titleContains?("HTTP 404 Not Found"));
    driver.quit();
}
catch(Exception e) {
    WebElement Username = driver.findElement(By.id("username"));
    Username.click(); 
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 undetected Selenium