我需要列出页面上的可点击元素吗?如何正确执行此操作?
可交互性/可点击性的预期条件为:
-
ElementToBeClickable Method (By(
public static Func<IWebDriver, IWebElement> ElementToBeClickable( By locator ) Parameters locator Type: OpenQA.Selenium.By The locator used to find the element. Return Value Type: Func<IWebDriver, IWebElement> The IWebElement once it is located and clickable (visible and enabled).
-
ElementToBeClickable Method (IWebElement(
public static Func<IWebDriver, IWebElement> ElementToBeClickable( IWebElement element ) Parameters element Type: OpenQA.Selenium.IWebElement The element. Return Value Type: Func<IWebDriver, IWebElement> The IWebElement once it is clickable (visible and enabled).
因此,可点击性/可交互性的预期条件都返回IWebElement。因此,您不能直接使用它们。
<小时 />解决方案
创建可点击元素列表的可能解决方案是使用以下任一预期条件:
-
VisibilityOfAllElementsLocationBy Method (By(
public static Func<IWebDriver, ReadOnlyCollection<IWebElement>> VisibilityOfAllElementsLocatedBy( By locator ) Parameters locator Type: OpenQA.Selenium.By The locator used to find the elements. Return Value Type: Func<IWebDriver, ReadOnlyCollection<IWebElement>> The list of IWebElement once it is located and visible.
-
VisibilityOfAllElementsLocationBy Method (ReadOnlyCollection(
public static Func<IWebDriver, ReadOnlyCollection<IWebElement>> VisibilityOfAllElementsLocatedBy( ReadOnlyCollection<IWebElement> elements ) Parameters elements Type: System.Collections.ObjectModel.ReadOnlyCollection<IWebElement> list of WebElements Return Value Type: Func<IWebDriver, ReadOnlyCollection<IWebElement>> The list of IWebElement once those are located and visible.