0

I am new to Selenium in C#. I tried to use

wait.Until(ExpectedConditions.ElementIsVisible(By.Id("someId")));
new SelectElement(driver.FindElement(By.Id("someId"))).SelectByText("someText");

I got error like this in my NUnit output:

OpenQA.Selenium.NoSuchElementException : Cannot locate element with text: someText

But when I replace wait.Unitil statement with Tread.Sleep(3000), my test could pass without error.

Need some help. Please advise.

  • most likely you're not giving enough time for the elements to load into the DOM before you try accessing them. – Chris Hawkes Dec 04 '15 at 21:38
  • @ChrisHawkes Do you mean the text element loading into the DOM? My point is why wait.Until does not work. – Peiyuan Zhou Dec 04 '15 at 21:47
  • Take a look at my answer on this post: http://stackoverflow.com/questions/23084078/selenium-c-sharp-webdriver-unable-to-find-element/24534900#24534900 – sparkyShorts Dec 04 '15 at 22:09

1 Answers1

1

It will work:

wait.Until(d => d.FindElement(By.XPath("//*[@id='someId']//*[text()='someText']")));
new SelectElement(driver.FindElement(By.Id("someId"))).SelectByText("someText");

But will be good to refactor this into single until, something like:

wait.Until(d =>
{
new SelectElement(d.FindElement(By.Id("someId"))).SelectByText("someText");
return d;
});
mdementev
  • 145
  • 10