Arun Prakash
Arun Prakash

Reputation: 121

C# Selenium - Click on a popup button

I want to Click on the Below popup Message button but even tho i placed the ID correctly, it doesnt get clicked. Throws No such Element Found Exception.

Popup Image

webDriver.Navigate().GoToUrl(url);
        try
        {
            await Task.Delay(1000);
            Logger.LogGenericText("Trying to Removed all Nicknames Cache...");
            webDriverwait.Until(d => d.FindElement(By.ClassName("namehistory_link"))).Click();
            webDriverwait.Until(d => d.FindElement(By.Id("NamePopupClearAliases"))).Click();
            webDriverwait.Until(d => d.FindElement(By.Id("btn_green_white_innerfade"))).Click();
        }
        catch (Exception ex)
        {
            Logger.LogGenericText(ex.ToString());
            return;
        }

Upvotes: 1

Views: 1230

Answers (1)

Arun Prakash
Arun Prakash

Reputation: 121

Ok so, Did some digging in the Driver Functions. This solved my issue.

webDriver.SwitchTo().ActiveElement().FindElement(By.XPath("/html/body/div[3]/div[2]/div/div[2]/div[1]/span")).Click();

Full working Code incase if anyone couldn't understand:

webDriver.Navigate().GoToUrl(url);
        try
        {
            await Task.Delay(1000);
            Logger.LogGenericText("Trying to Removed all Nicknames Cache...");
            webDriverwait.Until(d => d.FindElement(By.ClassName("namehistory_link"))).Click();
            await Task.Delay(2000);
            webDriverwait.Until(d => d.FindElement(By.XPath("//*[@id='NamePopupClearAliases']"))).Click();
            await Task.Delay(2000);
            webDriver.SwitchTo().ActiveElement().FindElement(By.XPath("/html/body/div[3]/div[2]/div/div[2]/div[1]/span")).Click();
            Logger.LogGenericText("All Nickname List Cleared.");
        }
        catch (Exception ex)
        {
            Logger.LogGenericText(ex.ToString());
            return;
        }

Upvotes: 1

Related Questions