0

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:

enter image description here

I have tried like:

driver.SwitchTo().Alert().Accept();

but it didn't worked, how to accept the popup?

good_shabes
  • 161
  • 7
  • Why don't you just download the extension beforehand and it to your chrome driver like this `options.add_extension("path_to_extension") driver = webdriver.Chrome(options=options, executable_path=r'path')` – Syed Azeem Javed Nov 29 '20 at 10:13
  • Take a look at [this](https://stackoverflow.com/questions/34222412/load-chrome-extension-using-selenium) article for reference. – Syed Azeem Javed Nov 29 '20 at 10:15
  • @SyedAzeemJaved Because that's not what I need... – good_shabes Nov 29 '20 at 10:43

1 Answers1

0
System.Windows.Forms.SendKeys.SendWait("{TAB}");
System.Windows.Forms.SendKeys.SendWait("{ENTER}");
Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • 5
    Please read [answer] and [edit] your answer to contain an explanation as to why this code would actually solve the problem at hand. Always remember that you're not only solving the problem, but are also educating the OP and any future readers of this post. – Adriaan Mar 27 '23 at 10:01