1

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;
            }
        }
sokolik745
  • 21
  • 2
  • Please share code how to implement WebDriverWait to find element here... – Om Prakash Jun 03 '16 at 08:21
  • 1
    Because I think here the problem is only that element is not getting fully loaded on DOM when you are going to find element... – Om Prakash Jun 03 '16 at 08:25
  • @Omi Sure, I updated my question... – sokolik745 Jun 03 '16 at 09:26
  • is this your complete html and is it static? no js in the page? – Moradnejad Jun 03 '16 at 09:29
  • @sokolik745 please follow this link to implement wait in correct way..http://stackoverflow.com/questions/6992993/selenium-c-sharp-webdriver-wait-until-element-is-present – Om Prakash Jun 03 '16 at 09:31
  • driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); use implicit wait before finding element...I think problem in your wait logic...check above link.. – Om Prakash Jun 03 '16 at 09:35
  • @Omi This did not work :( Btw. this wait I used was inspired by this artickle here [link] https://watirmelon.com/2014/01/29/waiting-in-c-webdriver/ – sokolik745 Jun 03 '16 at 10:53
  • @amanda No, this is not complete html. There is a javascript on this page which validates password strength but in different part. Yes, it is static :) – sokolik745 Jun 03 '16 at 12:20
  • Hi, I am having the same issue, is working perfectly in my computer but is failing in teamcity, any help, thanks – Marion Mar 30 '17 at 20:37

0 Answers0