怎样的webdriver等到元素是webdriver的C#点击 [英] Webdriver How to wait until the element is clickable in webdriver C#

查看:424
本文介绍了怎样的webdriver等到元素是webdriver的C#点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有是覆盖了几秒钟的所有元素的元素都在浏览器中产生之后,因为这方面,我所面临的问题的块UI,由于元件已进入存在的网络的驱动器尝试点击该元素,但点击被阻止UI好评。
我试图将等待直到但我并没有帮助,因为我可以在C#中的webdriver找到isClickAble

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();

有C#相当于isClickAble,在此先感谢

Is there C# equivalent for isClickAble ,Thanks in advance

推荐答案

好吧考虑看看到Java源代码,告诉我这基本上是做两件事情,以确定它是否是可点击

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

首先,它会检查它是否是通过标准的 ExpectedConditions.visibilityOfElementLocated 可见的,它会那么只需检查 element.isEnabled()真正或没有。

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.

这可以稍微凝聚,这基本上意味着(简化,在C#):​​

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


  1. 等到元素从DOM

  2. 返回
  3. 等到元素的 .Displayed 属性为true(这基本上是什么 visibilityOfElementLocated 是检查)。

  4. 等到元素的 .Enabled 属性为true(这基本上是什么 elementToBeClickable 正在检查)。

  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).

我想实现这个像这样(添加到当前的一组 ExpectedConditions的,但也有做这件事的多种方式:

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;
    };
}

在类似可用:

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



不过,您可能有一个什么样的点击可能意味着不同的想法,在这种情况下,该解决方案可能无法正常工作 - 但它是一个什么样的Java代码做一个直接翻译

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#点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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