C# - Get a full url print screen with ads

84 views Asked by At

I'm getting a full print screen from a url with Selenium. My problem is that the ads is not coming with the print. I don't know yet if it´s because the ads are dynamic or because the download time of the page. But I would like to ask if anyone has any idea on how to solve this problem?

Attached the image. And below is my code to clarify the question:

            ChromeOptions options = new ChromeOptions();
            options.AddArgument("--headless"); // Para executar o navegador em modo headless (sem interface gráfica)

            // Inicializa o driver do Chrome
            IWebDriver driver = new ChromeDriver(options);

            // Carrega a página da web
            string url = "https://www.uol.com.br";
            driver.Navigate().GoToUrl(url);

            // Define o tamanho da janela do navegador para ser maior do que a resolução do monitor
            IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
            int windowHeight = Convert.ToInt32(js.ExecuteScript("return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.body.clientHeight, document.documentElement.clientHeight);"));
            int windowWidth = Convert.ToInt32(js.ExecuteScript("return Math.max(document.body.scrollWidth, document.documentElement.scrollWidth, document.body.offsetWidth, document.documentElement.offsetWidth, document.body.clientWidth, document.documentElement.clientWidth);"));
            driver.Manage().Window.Size = new System.Drawing.Size(windowWidth, windowHeight);

            // Tira um screenshot da página inteira
            Screenshot screenshot = driver.TakeScreenshot();
            screenshot.SaveAsFile("screenshot.png", ScreenshotImageFormat.Png);

            // Fecha o navegador
            driver.Quit();

enter image description here

0

There are 0 answers