Handling of Frame and Frame-Set
Selenium Code:
12345678910111213141516171819 WebDriver driver = new ChromeDriver();driver.get("file:///C:/Automation/FrameProblem/FrameProblem.html");driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);//Switching to 2nd Parent Framedriver.switchTo().frame(1);//Switching to frame inside framesetdriver.switchTo().frame(0);//or//WebElement o_frameset = driver.findElement(By.tagName("frameset"));//WebElement o_frameset_frame = o_frameset.findElement(By.tagName("frame"));//driver.switchTo().frame(o_frameset_frame);WebElement obj = driver.findElement(By.tagName("input"));obj.sendKeys("Akash");
HTML which Above Code Handles:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<!DOCTYPE html> <html> <body> <h1>The Cascaded Frames Problem</h1> <div> <iframe src="./Frame1.html"> <!DOCTYPE html> <html> <body> <h3>Frame 1</h3> </body> </html> </iframe> <iframe src="./Frame2.html"> <!DOCTYPE html> <html> <frameset cols="25%,50%,25%"> <frame src ="./frame3.html"> <html> <body> <input type="text"></input> </body> </html> </frame> </frameset> </html> </iframe> </div> </body> </html> |