2014-02-25 14 views
0

我想檢查元素是否重點? 我試圖如何檢查該元素的重點在使用C#的硒webdriver#

Assert.True(Selenium.IsElementPresent("id=txtemail:focus")); 

而且這麼多的命令,但都顯示錯誤缺少集引用 的感謝!

+0

這是缺少一些事情。 「重點」是什麼意思?它對不同的應用程序有不同的含義。這是否意味着用戶可以看到它?這是否意味着它在屏幕的視口內?你得到什麼錯誤?缺少的程序集錯誤與您的斷言無關,或者您看到某個元素是否處於「焦點」,這意味着您沒有正確設置項目。發佈**整個**錯誤,它是**整個堆棧跟蹤**。 – Arran

回答

0

我開始了with this post,並以此擴展方法結束。座標屬性似乎是最佳使用價值。這可能會失敗,如果有2個元素在彼此頂部,但你可能不希望這樣。

/// <summary> 
/// Does the current element have focus? 
/// </summary> 
/// <param name="element">The element to test</param> 
/// <returns>If the element is focused.</returns> 
public static bool IsElementFocused(this RemoteWebElement element) 
{ 
    var focusedElement = ((IJavaScriptExecutor)UITestFramework.Browsers.Browser.Driver).ExecuteScript("return document.activeElement;") as RemoteWebElement; 
    return focusedElement != null && focusedElement.Coordinates.AuxiliaryLocator.ToString() == element.Coordinates.AuxiliaryLocator.ToString(); 
}