开发者

using regular expression in watin

开发者 https://www.devze.com 2023-01-06 05:10 出处:网络
I\'m using regular expression in watin. I have something like: ie.Button(Find.ByNam开发者_Go百科e(new Regex(input))).Click();

I'm using regular expression in watin.

I have something like: ie.Button(Find.ByNam开发者_Go百科e(new Regex(input))).Click(); but I wan't to click on the second or third button that match and not the first one.

How can I do this?


Try this:

ie.Button(Find.ByName(new Regex(input)) && Find.ByIndex(1 /* or 2 */)).Click();


Try this:

    ButtonCollection buttonCol = ie.Buttons;
    buttonCol = buttonCol.Filter(Find.ByName(new Regex(input)));
    buttonCol[1].Click();
    buttonCol[2].Click();


a lot of times I find the need to select a higher than first returned is because there are too few qualifiers on the find.by*() construct. you might try writing your own for cases like this that make more sense for your particular case.

example linq query:

var buttons = from e in browser.Buttons
            where e.Name == "Test" &&
            e.Text == "Button1"
            select e;

Something like this will allow you to select only what you want. It also gives you a way to check count quickly with a .ToList() @ the end of it. or use a foreach loop following to complete the actions needed.

0

精彩评论

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