Ana*_*d S 15 c# webdriver selenium-webdriver
在浏览器中生成元素后,有一个块Ui覆盖所有元素几秒钟,因为我面临一个问题,因为元素已经存在,web驱动程序尝试单击元素但是单击是Block UI收到.我曾尝试使用wait Until但我没有帮助,因为我可以在C#webdriver中找到isClickAble
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();
Run Code Online (Sandbox Code Playgroud)
isClickAble是否有C#等价物,提前谢谢
Arr*_*ran 32
好好看看Java源码,告诉我它基本上做了两件事来确定它是否是"可点击的":
首先,它会检查它是否是通过使用标准的"可见的" ExpectedConditions.visibilityOfElementLocated
,它会然后简单地检查是否element.isEnabled()
是true
或不是.
这可以稍微压缩,这基本上意味着(简化,在C#中):
.Displayed
属性为真(这实际上visibilityOfElementLocated
是检查的内容)..Enabled
属性为真(这实际上elementToBeClickable
是检查的内容).我会像这样实现它(添加到当前的一组ExpectedConditions
,但有多种方法:
/// <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;
};
}
Run Code Online (Sandbox Code Playgroud)
可用于:
var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
var clickableElement = wait.Until(ExpectedConditions.ElementIsClickable(By.Id("id")));
Run Code Online (Sandbox Code Playgroud)
但是,您可能对可点击的含义有不同的看法,在这种情况下,此解决方案可能无效 - 但它是Java代码正在执行的操作的直接转换.
归档时间: |
|
查看次数: |
61678 次 |
最近记录: |