FindElement does not return element text unless actually in DOM
I'm using Selenium's webdriver, but I've hit upon a problem.
I'm using KnockoutJS to bind my UI to data from the server. In my tests when I call FindElement(By.Id("InputField"))
it is returning the element ok, but unfortunately the Text() field is empty.
When I run a Jquery selector on the field:
$("#InputField").val()
it gives me the text in the input field ok.
When I inspect the Html source, there is no value in the input field, and I guess this is because KnockoutJS is binding the value to the input field late.
How do I get WebDriver to pull the attributes, text etc. from the field correctly rather than just empty text?
Instead of using the Text
property try using element.GetAttribute("value")
IWebElement element = _driver.FindElementById("InputField");
string value = element.GetAttribute("value");
精彩评论