I want to download chrome extension from chrome store via selenium all goes well except the popup that asks to confirm the download the extension. I have tried to accept the popup but it didn't worked, I'm adding the full code, only missing the part to accept the popup.
here my code (written in c#):
static void WebStoreDownload(string webdriverDirectory)
{
WebDriverWait wait;
ChromeOptions options = new ChromeOptions();
options.PageLoadStrategy = PageLoadStrategy.None;
options.AddArgument("no-sandbox");
options.SetLoggingPreference(LogType.Driver, LogLevel.All);
IWebDriver driver = new ChromeDriver(webdriverDirectory, options, TimeSpan.FromMinutes(1));
driver.Navigate().GoToUrl("https://chrome.google.com/webstore/category/extensions");
wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
wait.Until(condition => {
try
{
IWebElement serverTextBox = driver.FindElement(By.Id("searchbox-input"));
serverTextBox.Clear();
serverTextBox.SendKeys("malwarebyte");
serverTextBox.SendKeys(Keys.Enter);
return true;
}
catch (NoSuchElementException)
{
return false;
}
catch (ElementNotInteractableException)
{
return false;
}
});
wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
wait.Until(condition => {
try
{
IWebElement toClick = driver.FindElement(By.XPath("//*[contains(text(), 'Malwarebytes Browser Guard')]"));
toClick.Click();
return true;
}
catch (NoSuchElementException)
{
return false;
}catch(ElementNotInteractableException)
{
return false;
}
});
Thread.Sleep(3000);
wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
wait.Until(condition => {
try
{
IWebElement toClick = driver.FindElement(By.ClassName("g-c-R"));
toClick.Click();
return true;
}
catch (NoSuchElementException)
{
return false;
}
catch (ElementNotInteractableException)
{
return false;
}
});
}
and here is the popup:
I have tried like:
driver.SwitchTo().Alert().Accept();
but it didn't worked, how to accept the popup?