C#和断点 - 我们在这里有什么魔术师? [英] C# and breakpoints - do we have any magician in here?

查看:113
本文介绍了C#和断点 - 我们在这里有什么魔术师?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的:

public static void ByLinkText(string text)
{
    for (var i = 0; i < 50; i++)
    {
        try
        {
            Setup.Driver.FindElement(By.LinkText(text)).Click();
            return;
        }
        catch (Exception)
        {
        }
    }
}

(中间的奇怪的代码是硒 - 让刚刚跳过,这是不是这里的情况)

(The weird code in the middle is selenium - lets just skip that, it's not the case here)

好吧,所以我有这个 ByLinkText()方法,你不要在这里看到的,就是我重复此方法无限直到这中间啄能够正确执行,然后打的<$ 。C $ C>收益之后

Okay, so I have this ByLinkText() method, what you don't see here, is that I repeat this method infinitely until this middle thingy will execute correctly and then hit that return after.

所以:这中间代码不正确执行,我想知道为什么,所以我是什么在做什么?我把一个断点在catch部分。发生什么事?没有(和 ByLinkText()仍保持持续无限!)。

So: This middle code is NOT executing correctly, and I want to know why, so what am I doing? I put a breakpoint in the catch section. What is happening? Nothing (and ByLinkText() still keeps going infinitely!).

现在,你能告诉我:嘿!这中间代码只是不扔任何东西,但哦甜蜜的祝福......这中间的代码可以做两件事情:我要么扔东西,或做它喜欢它应该(的 prove1 和的 prove2 )。

Now, you would tell me "Hey! That middle code is just not throwing anything!", but oh sweet wishes... That middle code can do two things: either throw something at me, or do it like it should (prove1 and prove2).

因此,最后,这是怎么一回事呢?关于断点。当我把我的断点上收益(神奇的代码之后!)的代码执行正确!如何在programical世界是可能的,该断点修理我的应用程序!?

So finally, what is this all about? About breakpoints. As soon as I put my breakpoint on that return (right after magical code!) that code executes properly! HOW in the programical world is that possible, that breakpoint repairs my application!?

推荐答案

我觉得这更多的是与硒比你似乎相信。看一看寻找元素隐性和显性的等待。

I think this has more to do with selenium than you seem to believe. Have a look at implicit and explicit waits for finding the element.

HTTP://docs.seleniumhq。组织/文档/ 04_webdriver_advanced.jsp

试试另一件事情是保存IWebElement导致到一个临时变种,穿上小觉,然后单击它。有时浏览器的用户界面不能处理的命令一样快,硒发出它们。

Another thing to try is to save the IWebElement result into a temp var, put on small sleep and then click it. Sometimes the browser ui can't handle the commands as fast as selenium issues them.

var el = Setup.Driver.FindElement(By.LinkText(text));
Thread.Sleep(750);
el.Click();

这篇关于C#和断点 - 我们在这里有什么魔术师?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆