Created
August 10, 2022 01:54
-
-
Save bharathmuddada/a6988ab1b5f0a1fc9533a5af16db9c84 to your computer and use it in GitHub Desktop.
c# selenium code to handle nested frames
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SeleniumHandlingNestedFrames { | |
public static void Main(string[] args) | |
{ | |
new DriverManager().SetUpDriver(new ChromeConfig()); | |
var driver = new ChromeDriver(); | |
driver.Manage().Window.Maximize(); | |
driver.Navigate().GoToUrl("https://the-internet.herokuapp.com/nested_frames"); | |
var frameelement = driver.FindElement(By.XPath("//frame[@name='frame-top']")); | |
driver.SwitchTo().Frame(frameelement); | |
var frames = driver.FindElements(By.TagName("frame")); | |
// var frameelement2 = driver.FindElement(By.XPath("//frame[@name='frame-left']")); | |
Console.WriteLine("window handles : " + driver.WindowHandles); | |
foreach (var frame in frames) | |
{ | |
Console.WriteLine("framename " + frame); | |
driver.SwitchTo().Frame(frame); | |
var framebody = driver.FindElement(By.TagName("body")); | |
Console.WriteLine(framebody.Text); | |
driver.SwitchTo().ParentFrame(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment