开发者

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.

开发者_JS百科

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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜