Question

I am trying to fill an input matching a given CSS selector using WatiN. Here is a code sample:

public ActionResult Do(WebScraper webScraper)
        {
            var target = webScraper.Browser.Element(Find.BySelector(TargetSelector));
            if (target == null)
            {
                return ActionResult.Failure(string.Format("No element found matching selector '{0}'.", TargetSelector));
            }

            target.SetAttributeValue("value", Value);
            return ActionResult.Success();
        }

Testing with a TargetSelector being "#someID". Did inspect the page right before this is executed and I can see a <input id="someID" ... ></input>

Getting an error that looks like this:

Could not find Element Tag matching Criteria: Selector = '#someID'

Thanks,

Was it helpful?

Solution

Using Elements.Filter, gave the expected result... Using that instead.

//var target = webScraper.Browser.Element(Find.BySelector(TargetSelector));
var target = webScraper.Browser.Elements.Filter(Find.BySelector(TargetSelector)).FirstOrDefault();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top