那麼考慮看看進入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#):
- 等待直到元件從DOM
- 等待返回直到該元素的
.Displayed
屬性爲true(基本上是什麼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;
};
}
可用的東西,如:
var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
var clickableElement = wait.Until(ExpectedConditions.ElementIsClickable(By.Id("id")));
然而,您可能對可點擊的可能意味着什麼有不同的想法,在這種情況下,此解決方案可能無法正常工作 - 但它是Java代碼所做的直接翻譯G。
感謝ü上述問題我提到的是由於有塊UI,我解決了這個問題,您的解決方案幫我解決一個不同的問題再次感謝u.Your的解決方案是正確的解決方案,它代表了isClickAble正確 –
此解決方案不會確保該元素是* Clickable *。元素可以是'Displayed'和'Enabled',但是*不可點擊*由於**其他元素會收到點擊**。 –
@AlexOkrushko,展開你的意思,給出可重複的場景,例子,完整的錯誤等等。我希望在檢查'.Displayed'和'.Enabled'這兩個錯誤消息,但它不是一件確定的事情,那裏很可能是邊緣案例 - 因此,我會請你提出一個實際情況,情況並非如此。這應該然後提交作爲一個問題的硒開發的。 – Arran