在 watin 中使用正则表达式

发布于 2024-09-08 07:56:53 字数 149 浏览 1 评论 0原文

我在 watin 中使用正则表达式。

我有类似的东西: ie.Button(Find.ByName(new Regex(input))).Click(); 但我不想单击第二个或第三个匹配的按钮,而不是第一个按钮。

我该怎么做?

I'm using regular expression in watin.

I have something like: ie.Button(Find.ByName(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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你的笑 2024-09-15 07:56:53

试试这个:

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

Try this:

ie.Button(Find.ByName(new Regex(input)) && Find.ByIndex(1 /* or 2 */)).Click();
无需解释 2024-09-15 07:56:53

试试这个:

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

Try this:

    ButtonCollection buttonCol = ie.Buttons;
    buttonCol = buttonCol.Filter(Find.ByName(new Regex(input)));
    buttonCol[1].Click();
    buttonCol[2].Click();
囍孤女 2024-09-15 07:56:53

很多时候我发现需要选择比第一次返回的更高的值是因为 find.by*() 构造上的限定符太少了。您可以尝试为这样的情况编写自己的代码,这对您的特定情况更有意义。

linq 查询示例:

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

类似这样的内容将允许您仅选择您想要的内容。它还为您提供了一种通过 .ToList() @ 末尾快速检查计数的方法。或者使用下面的 foreach 循环来完成所需的操作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文