We are doing password management solutions for our client. We are able to sucessfully automate the username and password using puppeter sharp using the following code.
But after the program execution the browser closes automatically. Is there anyway to leave the browser running after program execution.
static async Task Main(string[] args)
{
var options = new LaunchOptions { Headless = false, ExecutablePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", Args = new string[] { "--no-sandbox" } };
using (var browser = await Puppeteer.LaunchAsync(options))
using (var page = await browser.NewPageAsync())
{
// use page
await page.GoToAsync("https://accounts.google.com/");
//await page.WaitForNavigationAsync();
// await page.WaitForSelectorAsync("type=email");
// await page.ClickAsync("type=email");
// await page.WaitForNavigationAsync();
await Task.Delay(2000);
//TODO : change to your email
await page.TypeAsync("#identifierId", "someusername@gmail.com");
await page.WaitForSelectorAsync("#identifierNext");
await page.ClickAsync("#identifierNext");
await Task.Delay(2000);
await page.WaitForSelectorAsync(@"input[type='password']");
await Task.Delay(2000);
await page.ClickAsync(@"input[type='password']");
await Task.Delay(2000);
//TODO : change to your password
await page.TypeAsync(@"input[name='password']", "somepassword");
await Task.Delay(2000);
await page.WaitForSelectorAsync("#passwordNext");
await Task.Delay(2000);
await page.ClickAsync("#passwordNext");
await Task.Delay(2000);
await page.WaitForNavigationAsync();
}
}
If you want to automate a browser, then leave it open for user interaction, you will need to launch the browser before automating it, and have your code attach to that browser instance. This question gives some info on how to do that:
Puppeteer C#: Connecting to Running Chrome Instance
And this article goes into greater detail on that strategy:
https://medium.com/@jaredpotter1/connecting-puppeteer-to-existing-chrome-window-8a10828149e0