https://www.gcreddy.com/2021/04/selenium-tutorial-for-beginners.html
Handling Web Frames using Selenium WebDriver

HTML Frames are used to divide the Browser window into multiple sections
Frames are sections of a web page displayed on the Top window
In Manual Testing we need not focus on Frames, we can handle any element in any frame directly.
In Automated Testing or Test Automation using Selenium, first, we need to switch to a frame from the Topwindow then we can operate element/s in that frame.

Example: Incorrect script

System.setProperty("webdriver.chrome.driver", "D://chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();

driver.get("https://www.selenium.dev/selenium/docs/api/java/index.html?overview-summary.html");
driver.findElement(By.linkText("org.openqa.selenium")).click();

Switch from Top window to a Frame is done in two ways

1. Using Frame Index
driver.switchTo.frame(int index);

2. Using Frame Name
driver.switchTo.frame(String name);

Using 'Frame Index'

System.setProperty("webdriver.chrome.driver", "D://chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();

driver.get("https://www.selenium.dev/selenium/docs/api/java/index.html?overview-summary.html");
driver.switchTo().frame(2);
driver.findElement(By.linkText("org.openqa.selenium")).click();

Using 'Frame Name'

System.setProperty("webdriver.chrome.driver", "D://chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();

driver.get("https://www.selenium.dev/selenium/docs/api/java/index.html?overview-summary.html");
driver.switchTo().frame("classFrame");
driver.findElement(By.linkText("org.openqa.selenium")).click();

Test Steps:

Launch a web page that has multiple frames
Operate an Element in 3rd Frame
Operate an Element in 1st Frame
Close Browser Window

Manual Testing:
Launch a Browser
Load/Open a web page that has multiple frames
Operate an Element in 3rd Frame
Operate an Element in 1st Frame
Close Browser Window

Automated Testing using Selenium
Launch a Browser
Load/Open a web page that has multiple frames
Switch from Top window to 3rd Frame
Operate an Element in 3rd Frame
Back to To window (default)
Switch from Top window to 1st Frame
Operate an Element in 1st Frame
Close Browser Window

Selenium WebDriver Test Steps:

System.setProperty("webdriver.chrome.driver", "D://chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();

driver.get("https://www.selenium.dev/selenium/docs/api/java/index.html?overview-summary.html");
driver.switchTo().frame(2);
Thread.sleep(3000);
driver.findElement(By.linkText("org.openqa.selenium")).click();
Thread.sleep(3000);

driver.switchTo().defaultContent();

driver.switchTo().frame(0);
driver.findElement(By.linkText("org.openqa.selenium.chrome")).click();
Thread.sleep(3000);

driver.close();