Skip to content

Instantly share code, notes, and snippets.

@thgiang
Created March 2, 2021 16:17
Show Gist options
  • Save thgiang/e222f036806f126f51a0b75a81956c20 to your computer and use it in GitHub Desktop.
Save thgiang/e222f036806f126f51a0b75a81956c20 to your computer and use it in GitHub Desktop.
Control real chrome browser without notice: "Chrome is being controlled by automated test software"
Random rd = new Random();
string remote_port = rd.Next(9000, 9999).ToString();
// Open real Chrome
Process process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.FileName = "chrome";
process.StartInfo.Arguments = "https://thgiang.com --load-extension=\"C:\\Users\\Admin\\Desktop\\my_extension\" --disable-gpu --new-window --remote-debugging-port=" + remote_port + " --user-data-dir=\"C:\\Profile\" --proxy-server=\""+proxy+"\" --disable-infobars --disable-notifications --window-size=1366,768"; //--window-position=0,0 --window-size=1200,800 --disable-images
process.Start();
Thread.Sleep(1000);
var options = new ChromeOptions { DebuggerAddress = "localhost:" + remote_port };
ChromeDriverService sv = ChromeDriverService.CreateDefaultService();
sv.HideCommandPromptWindow = true;
var driver = new ChromeDriver(sv, options);
// Close all current tabs
while (true)
{
var tabs = driver.WindowHandles;
if (tabs.Count > 1)
{
try
{
driver.SwitchTo().Window(tabs[1]);
driver.Close();
driver.SwitchTo().Window(tabs[0]);
}
catch { }
}
else
{
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment