2

I'm developing an web application that monitor changes in other websites. I came across some of the websites and that contain load of Frame set and Frames.

I'm using the below code:

  var chromeOption = new ChromeOptions();
        chromeOption.AddArgument("--headless");
        Console.WriteLine("Getting into the Application");
        using (var driver = new ChromeDriver(chromeOption))
        {
            Console.WriteLine("Loading the Web Page");

            driver.Navigate().GoToUrl("http://www.juljensen.dk/");
            var htmltxt = driver.PageSource;
        }

The Page Source returns me:

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>
    <title>Mr X. Consulting</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
</head>
<frameset cols="25%,50%,25%" frameborder="0">
  <frame src="border.html" />
  <frame src="jjc.html" />
  <frame src="border.html" />
</frameset>

The PageSource is not loading the frame source. I have searched a lot online, even here in vain but didn't get useful info.

My question is how can I load all the frames and get the whole page source like below (only from Inspect element from Chrome)

Page Source from Chrome Inspect Element

1 Answer 1

0

To load all the frames and get the complete page source using Selenium ChromeDriver, you can use the following code:

var chromeOption = new ChromeOptions();
chromeOption.AddArgument("--headless");
Console.WriteLine("Getting into the Application");
using (var driver = new ChromeDriver(chromeOption))
{
    Console.WriteLine("Loading the Web Page");

    driver.Navigate().GoToUrl("http://www.juljensen.dk/");
    var mainHandle = driver.CurrentWindowHandle;
    var handles = driver.WindowHandles;

    foreach (var handle in handles)
    {
        if (handle != mainHandle)
        {
            driver.SwitchTo().Window(handle);
            var htmltxt = driver.PageSource;
            Console.WriteLine(htmltxt);
        }
    }
}

This code switches to each frame and gets the page source of each frame. The complete page source can be combined from the page source of each frame.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.