0
I tried to implement the Chrome Options
in my script to delete that yellow bar of Chrome information, which is displayed every time we are running automated tests ("Chrome is being Controlled by Automated test software"), but the result I had was the display of two Chrome windows: one minimized, displaying the infobar, and the other maximized without the infobar view, where my script was executed.
Please, would you know where I am going wrong? I have made several modifications but I could not fix this double browser opening:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace navegador.PageObjects
{
public class acessaSite
{
public IWebDriver driver;
public acessaSite(IWebDriver driver)
{
this.driver = driver;
}
public void acessaURL()
{
var options = new ChromeOptions();
options.AddArguments("--disable-infobars");
options.AddUserProfilePreference("credentials_enable_service", false);
options.AddUserProfilePreference("profile.password_manager_enabled", false);
driver = new ChromeDriver(options);
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("https://meusite.com.br");
Thread.Sleep(1000);
}
}
}
Grateful!
Hi Bruno, thanks for the tip, but even using explicitly not yet worked... just the fact of instantiating Chromeoptions, the code is already lost:
ChromeOptions options = new ChromeOptions();
driver = new ChromeDriver(options);
– CarolCiola
Debugging realized that the second window is being opened when running
driver.Manage().Window.Maximize();
– CarolCiola
Hi Carol, I couldn’t reproduce this scenario here, but what you do is change the maximize command by the following argument
options.AddArguments("start-maximized");
– Bruno Prior
Bruno, even changing this excerpt, the script gets lost and opens the other window when calling the driver:
driver.Navigate().GoToUrl("https://www.meusite.com.br");
. Is there any argument or something to access URL? I searched the internet but could not find.– CarolCiola
@Carolciola, not just seen, but the constructor you created called "accessSite" also calls the driver, so I guess when the driver is called he ends up opening two browsers.
– Bruno Prior
Bruno, I was able to solve the question. This class has a constructor because it is called by a main class. So the correct thing would be to increment the main class script with Chromeoptions, not this example class. The main class instantiated the driver, and when calling this example class, the driver coming from the main one was "thrown away" and another without any properties was opened.
– CarolCiola