OpenQA.Selenium.NoSuchElementException - C# Selenium

Viewed 9340

A text has to be entered in a Textbox, a list auto-extends, and I need to select the first item. But it fails due to the exception; OpenQA.Selenium.NoSuchElementException. I tried using wait.Until(), but facing the same error.

Screenshot

try
{
     IWebElement cityList = driver.FindElement(By.XPath("value"));
     MouseClick(driver, cityList);
}
catch (OpenQA.Selenium.NoSuchElementException ex)
{
     IWebElement cityList = driver.FindElement(By.XPath("value"));
     MouseClick(driver, cityList);
}

Edit

HTML code:

<input name="ctl00$cphmain$txtCity" type="text" maxlength="50" id="ctl00_cphmain_txtCity" class="mandsearchtxtbox" onkeypress="javascript:return ValidateInputAlphabeticValuesOnly(event);" onblur="javascript:return checkItemMsg(this)" style="width:180px;" autocomplete="off">
<div class="AutoExtenderHighlight">AMANDOLUWA</div>

Code with wait.Until()

WebDriverWait wait1 = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
    wait.Until<IWebElement>((d) =>
        {
            try
            {
                return d.FindElement(By.XPath("//*[@id='citydiv']/div"));
                MouseClick(driver, driver.FindElement(By.XPath("//*[@id='citydiv']/div")));
            }
            catch (OpenQA.Selenium.NoSuchElementException ex)
            {
                return null;
                MouseClick(driver, driver.FindElement(By.XPath("//*[@id='citydiv']/div")));
            }
        });

Edit 2

HTML code for WebDriverException(Button)

HTML code

1 Answers
Related