<bdo id='HdpDa'></bdo><ul id='HdpDa'></ul>

  1. <i id='HdpDa'><tr id='HdpDa'><dt id='HdpDa'><q id='HdpDa'><span id='HdpDa'><b id='HdpDa'><form id='HdpDa'><ins id='HdpDa'></ins><ul id='HdpDa'></ul><sub id='HdpDa'></sub></form><legend id='HdpDa'></legend><bdo id='HdpDa'><pre id='HdpDa'><center id='HdpDa'></center></pre></bdo></b><th id='HdpDa'></th></span></q></dt></tr></i><div id='HdpDa'><tfoot id='HdpDa'></tfoot><dl id='HdpDa'><fieldset id='HdpDa'></fieldset></dl></div>
    <tfoot id='HdpDa'></tfoot>

  2. <small id='HdpDa'></small><noframes id='HdpDa'>

    1. <legend id='HdpDa'><style id='HdpDa'><dir id='HdpDa'><q id='HdpDa'></q></dir></style></legend>

    2. Webdriver如何等到元素在webdriver C#中可点击

      时间:2023-09-13

      1. <legend id='CL7B9'><style id='CL7B9'><dir id='CL7B9'><q id='CL7B9'></q></dir></style></legend>
            <bdo id='CL7B9'></bdo><ul id='CL7B9'></ul>
            <i id='CL7B9'><tr id='CL7B9'><dt id='CL7B9'><q id='CL7B9'><span id='CL7B9'><b id='CL7B9'><form id='CL7B9'><ins id='CL7B9'></ins><ul id='CL7B9'></ul><sub id='CL7B9'></sub></form><legend id='CL7B9'></legend><bdo id='CL7B9'><pre id='CL7B9'><center id='CL7B9'></center></pre></bdo></b><th id='CL7B9'></th></span></q></dt></tr></i><div id='CL7B9'><tfoot id='CL7B9'></tfoot><dl id='CL7B9'><fieldset id='CL7B9'></fieldset></dl></div>
              • <small id='CL7B9'></small><noframes id='CL7B9'>

                <tfoot id='CL7B9'></tfoot>

                  <tbody id='CL7B9'></tbody>
                本文介绍了Webdriver如何等到元素在webdriver C#中可点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在浏览器中生成元素后,有一个块 Ui 覆盖了所有元素几秒钟,因此我面临一个问题,由于元素已经存在,网络驱动程序尝试单击该元素,但是Block UI 接收到点击.我曾尝试使用等待直到但我没有帮助,因为我可以在 C# webdriver 中找到 isClickAble

                 var example = _wait.Until((d) => d.FindElement(By.XPath("Example")));var example2 = _wait.Until<IWebElement>(ExpectedConditions.ElementIsVisible(By.XPath("Example")));example.click();example2.click();

                isClickAble 是否有 C# 等价物,在此先感谢

                解决方案

                看看 Java 源代码,告诉我它基本上是在做两件事来确定它是否可点击":

                https://code.google.com/p/selenium/source/browse/java/client/src/org/openqa/selenium/support/ui/ExpectedConditions.java

                首先,它会使用标准的 ExpectedConditions.visibilityOfElementLocated 检查它是否可见",然后它会简单地检查 element.isEnabled() 是否true 与否.

                这可以稍微浓缩,这基本上意味着(简化,在 C# 中):

                1. 等到元素从 DOM 返回
                2. 等到元素的 .Displayed 属性为真(这实际上是 visibilityOfElementLocated 正在检查的内容).
                3. 等到元素的 .Enabled 属性为真(这实际上是 elementToBeClickable 正在检查的内容).

                我会这样实现(添加到当前的 ExpectedConditions 集,但是有多种方法可以做到:

                ///<总结>///检查元素是否可见的期望.///</总结>///<param name="locator">用于查找元素的定位器.</param>///<returns><see cref="IWebElement"/>一旦它被定位,可见和可点击.</returns>公共静态函数<IWebDriver,IWebElement>ElementIsClickable(按定位器){返回驱动程序=>{var element = driver.FindElement(locator);返回(元素!= null && element.Displayed && element.Enabled)?元素:空;};}

                可用于:

                var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));var clickableElement = wait.Until(ExpectedConditions.ElementIsClickable(By.Id("id")));

                但是,您可能对 clickable 的含义有不同的理解,在这种情况下,此解决方案可能不起作用 - 但它是对 Java 代码所做工作的直接翻译.p>

                There is a block Ui which covers all the elements for a few seconds after the Element have been generated in the browser because of this i facing a problem ,Since element has come into existence the web-driver try to click the element but the click is received by Block UI . I have tried to use the wait Until but i did not help ,Since i can find isClickAble in C# webdriver

                   var example = _wait.Until<IWebElement>((d) => d.FindElement(By.XPath("Example")));
                   var example2 = _wait.Until<IWebElement>(ExpectedConditions.ElementIsVisible(By.XPath("Example")));
                example.click();
                example2.click();
                

                Is there C# equivalent for isClickAble ,Thanks in advance

                解决方案

                Well taking a look into the Java source, tells me it is basically doing two things to determine if it's 'clickable':

                https://code.google.com/p/selenium/source/browse/java/client/src/org/openqa/selenium/support/ui/ExpectedConditions.java

                Firstly, it'll check if it's 'visible' by using the standard ExpectedConditions.visibilityOfElementLocated, it'll then simply check if the element.isEnabled() is true or not.

                This can be condensed slightly, this basically means (simplified, in C#):

                1. Wait until the element is returned from the DOM
                2. Wait until the element's .Displayed property is true (which is essentially what visibilityOfElementLocated is checking for).
                3. Wait until the element's .Enabled property is true (which is essentially what the elementToBeClickable is checking for).

                I would implement this like so (adding onto the current set of ExpectedConditions, but there are multiple ways of doing it:

                /// <summary>
                /// An expectation for checking whether an element is visible.
                /// </summary>
                /// <param name="locator">The locator used to find the element.</param>
                /// <returns>The <see cref="IWebElement"/> once it is located, visible and clickable.</returns>
                public static Func<IWebDriver, IWebElement> ElementIsClickable(By locator)
                {
                    return driver =>
                    {
                        var element = driver.FindElement(locator);
                        return (element != null && element.Displayed && element.Enabled) ? element : null;
                    };
                }
                

                Usable in something like:

                var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
                var clickableElement = wait.Until(ExpectedConditions.ElementIsClickable(By.Id("id")));
                

                However, you might have a different idea of what clickable might mean, in which case, this solution may not work - but it is a direct translation of what the Java code is doing.

                这篇关于Webdriver如何等到元素在webdriver C#中可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 Selenium 2 中截取测试屏幕截图的最佳方法是什么? 下一篇:Selenium WebDriver 和浏览器选择文件对话框

                相关文章

                <legend id='SaZcZ'><style id='SaZcZ'><dir id='SaZcZ'><q id='SaZcZ'></q></dir></style></legend>

                    <bdo id='SaZcZ'></bdo><ul id='SaZcZ'></ul>
                1. <tfoot id='SaZcZ'></tfoot>

                    <small id='SaZcZ'></small><noframes id='SaZcZ'>

                  1. <i id='SaZcZ'><tr id='SaZcZ'><dt id='SaZcZ'><q id='SaZcZ'><span id='SaZcZ'><b id='SaZcZ'><form id='SaZcZ'><ins id='SaZcZ'></ins><ul id='SaZcZ'></ul><sub id='SaZcZ'></sub></form><legend id='SaZcZ'></legend><bdo id='SaZcZ'><pre id='SaZcZ'><center id='SaZcZ'></center></pre></bdo></b><th id='SaZcZ'></th></span></q></dt></tr></i><div id='SaZcZ'><tfoot id='SaZcZ'></tfoot><dl id='SaZcZ'><fieldset id='SaZcZ'></fieldset></dl></div>