Cannot find dynamically generated list item of unordered list

Nov 28, 2012 at 7:09 PM

Hi all,

I have a jQuery UI scripted front end that uses the auto complete ddl from that library.  After having set the text in the input to a previously known value the drop down list box displays the partially matching list items.  I know that these list items are there as I have validated it in both Chrome and IE 9 using the developer tools feature of both browsers. 

To facilitate the find, I create and assign an id for each list item however it is not finding anything and fails. 

Just curious, when I set the edit text prior to trying to find said list item is it possible that it is trying to find via the current context of the input (Text Box).  If so is there a way to go back to the root of the document so that I can find from there?

Here is my code...

        public void CORSHomeUITest2696()
            // test DDL Auto-Complete box
            // set the text of the DDL

            // Now find the various children
  • // Adams County, WA // var foundText = TestedPage.GetAutoCompleteHyperLinkText("Adams County, WA"); Assert.AreEqual(foundText, "Adams County, WA"); } // then in my HomePage class ... public void SetDdlAllJurisdictionOptionText(string setTextTo) { Browser.SetEditText("auto-complete-input", setTextTo); } public string GetAutoCompleteHyperLinkText(string listItemId) { // the next statement fails to find anything var ddlListItem = Browser .Find(new { Id = listItemId, TagName = "li" }); var anchor = ddlListItem.GetChildren().First(); return anchor.GetInnerText(); }
  • Nov 28, 2012 at 7:46 PM

    I found the correction.  It appears, and this is just a guess, that because I previously set the input text which has to find the input tag in order to set its text the context of the Browser object has changed, is this the case?  At any rate if I search from the Browser.TopParent I easily find what I am looking for. 

    Here is the code with the correction...

            public string GetAutoCompleteHyperLinkText(string listItemId)
                // need to start looking from the top of the document in case
                // context has been changed by the previous statement
                var ddlListItem = Browser.TopParent
                   .Find(new { Id = listItemId, TagName = "li" });
                var anchor = ddlListItem.GetChildren().First();
                return anchor.GetInnerText();