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();
}
}