I know that there are a lot of question on the problem "Unable to locate element" but none of the answers work for me.
Example from my test looks like:
driver.FindElementById("OldPassword").Clear();
driver.FindElementById("OldPassword").SendKeys("Admin666*");
When I run tests on my computer it works well but after it fails on a TeamCity agent with this error:
Test method CLSTesting.AccountControllerTests.TestManagePasswordChrome threw exception: OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"OldPassword"}
Adding implicit waits or waiting until element is present doesn't work and there is no iframe to switch on. I tried to change the find element method but I am getting the same error again. It seems that this error is random but mostly the test fails. Here is the html example:
<div class="form-group">
<label class="col-md-2 control-label" for="OldPassword">Current password:</label>
<div class="col-md-10">
<input class="form-control" id="OldPassword" name="OldPassword" type="password" />
</div>
</div>
Do you have any idea where is the problem? Thank you!
UPDATE - extension methods which I use for waiting for element:
public static bool WaitUntilElementIsPresent(this IWebDriver driver, By by, int timeout = 20)
{
for (var i = 0; i < timeout; i++)
{
if (driver.ElementIsPresent(by)) return true;
Thread.Sleep(500);
}
return false;
}
public static bool ElementIsPresent(this IWebDriver driver, By by)
{
try
{
return driver.FindElement(by).Displayed;
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
return false;
}
}