How to fire a JQuery selector from WatiN

2019-08-27 13:47发布

I am using watin to test a web page. The vast majority of which works fine. But I have a function that is run using JQuery. When the option of a SelectList is changed. When I run the browser and I have a break point in the js code the following jquery selector is fired.

$("#OwningRegion").change(function () {

But I cannot cause this to happen with watin. I have tried the FireEvent("change"). I have tried FireEvent("onClick"). I have tried .Option[1].Click(). etc.

标签: c# jquery watin
2条回答
霸刀☆藐视天下
2楼-- · 2019-08-27 14:19

jQuery-style selector support is now built-in to WaTiN 2.0:

A new method Find.BySelector is added. It accepts any valid jQuery/Sizzle CSS selector string. The following scenarios are supported:

var element = browser.Element(Find.BySelector(…));
var div = browser.Div(Find.BySelector(…));
var elements = browser.Elements.Filter(Find.BySelector(…));
var buttons = browser.Buttons.Filter(Find.BySelector(…));
查看更多
成全新的幸福
3楼-- · 2019-08-27 14:33

Try this one:

browser.Eval(string.Format("$('#{0},.{0}').change();", id)); //Both for classes and id's
查看更多
登录 后发表回答