I am looking for the following element:
<input id="login_input" value="" class="input_long " type="text" name="login" tabindex="1">
This element is being loaded by javascript after the initial page was fully loaded. Now this is my code for obtaining this element:
IWebDriver _drv = new ChromeDriver();
_drv.Navigate().GoToUrl("http://mysite.com");
System.Threading.Thread.Sleep(2000);
do
{
try
{
_drv.FindElement(By.Id("login_input")).SendKeys("555567756756");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
} while (true);
The error it gives me is saying A first chance exception of type 'OpenQA.Selenium.NoSuchElementException' occurred in WebDriver.dll, when clearly this element is visible on the site.
What can I do to obtain this element?
Update: Changed my code a little bit:
IWebDriver _drv = new ChromeDriver();
_drv.Url = "http://mysite.com";
//_drv.Navigate().GoToUrl("http://mysite.com");
do
{
try
{
WaitUntilPresent(By.Id("login_input")).SendKeys("555567756756");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
} while (true);
IWebElement WaitUntilPresent(By element)
{
return new WebDriverWait(_drv, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementExists(element));
}
The above gives me timeout exception, this is because _drv.PageSource is not being updated after javascript on the page has loaded element.