jeudi 28 février 2019

Unreachable code detected in IF/ELSE statement

I need some assistance please... I am having problems with the ELSE statement, the code executes whatever that is in the IF bracket but never reach the ELSE bracket. It works without issues with Chrome but fail every time with IE. This is my code:

IWait<IWebDriver> wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(3.00));
        IList<IWebElement> boxList = _driver.FindElements(By.CssSelector("ListBox option"));

        bool textExists = false;

        foreach (var option in boxList)
        {
            if (option.Text.Equals("TEST"))
            {
                textExists = true;
                break;
            }
        }

        if (!textExists)
        {
            _driver.FindElement(By.Id("AddButton")).Click();

            var newRecordInfo = table.CreateSet<FeatureInfo>();

            foreach (var recordData in newRecordInfo)
            {
                _driver.FindElement(By.Id("DescTextBox")).SendKeys(recordData._discription);
                _driver.FindElement(By.Id("PaTextBox")).SendKeys(recordData._score);

                new SelectElement(_driver.FindElement(By.Id("DropDown"))).SelectByValue("1");
                _driver.FindElement(By.Id("SaveButton")).Click();
            }
        }
        else 
        {
            SelectElement Select = new SelectElement(_driver.FindElement(By.Id("ListBox")));
            Select.SelectByText("TEST");

            _driver.FindElement(By.Id("DeleteButton")).Click();

            IAlert alert = _driver.SwitchTo().Alert();
            alert.Accept();

            //IJavaScriptExecutor js = (IJavaScriptExecutor)_driver;
            //js.ExecuteScript("window.confirm = function(msg) { return true; }");

            Thread.Sleep(1000);


        }

Aucun commentaire:

Enregistrer un commentaire