0

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

Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
Wilton
  • 218
  • 2
  • 11
  • 1
    I removed the request for a component or tool, since these kinds of requests are explicitly off-topic. If the goal really is to get a tool recommendation, delete this question and consider posting it on [Software Recommendations](https://softwarerecs.stackexchange.com/help/on-topic) instead. – Greg Burghardt May 10 '23 at 13:29

0 Answers0