Selenium中预期条件的用法描述(最全面)

财经 网编 2023-07-14 08:52 168 0
注:从原文档一个个扒出来翻译的,有不对的地方还请批评指正。
1、 titleIs( String title)

判断当前页面的title是否精确等于预期

2、 titleContains( String title)

判断当前页面的title是否包含预期字符串

3、 urlToBe( String url)

判断当前页面的url是否精确等于预期

4、 urlContains( String fraction)

判断当前页面的url是否包含预期字符串

5、 urlMatches( String regex)

字符串正则表达式

6、 presenceOfElementLocated( By locator)

判断元素是否出现,只要有一个元素出现,就通过。(代表在不代表可见)
判断是否至少有 1 个元素存在于 dom 树中。举个例子,如果页面上有 n 个元素的 class 都是’column-md-3’,那么只要有 1 个元素存在,这个方法就返回 True。

7、 presenceOfElementsLocated( By locator)

判断元素是否出现,必须所有符合条件的元素都加载出来,才通过。

8、 elementIfVisible(WebElement element)

如果给定元素是可见的且具有非零大小,否则为null

9、presenceOfAllElementsLocatedBy( By locator)

判断元素是否出现。

10、 visibilityOfElementLocated( By locator)

传入类型为:locator
判断某个元素是否可见. 可见代表元素非隐藏,并且元素宽和高都不等于 0

11、visibilityOfAllElementsLocatedBy( By locator)

判断某组元素是否可见

12、visibilityOfAllElements(final List<WebElement> elements)

传入类型为:element
判断某个元素是否可见. 可见代表元素非隐藏,并且元素宽和高都不等于 0

13、textToBePresentInElement( WebElement element, String text)

判断某个元素中的text是否包含了预期的字符串;

14、textToBePresentInElement(By locator, String text)

判断某个元素中的 text 是否 包含 了预期的字符串

15、textToBePresentInElementLocated(final By locator, final String text)

判断某个元素中的 text 是否 包含 了预期的字符串

16、textToBePresentInElementValue( WebElement element, String text)

判断某个元素中的 value 属性是否包含 了预期的字符串

17、textToBePresentInElementValue(final By locator, final String text)

判断某个元素中的 value 属性是否包含 了预期的字符串

18、frameToBeAvailableAndSwitchToIt(final String frameLocator)

断该 frame 是否可以 switch进去,如果可以的话,返回 True 并且 switch 进去,否则返回 False

19、frameToBeAvailableAndSwitchToIt(final By locator)

断该 frame 是否可以 switch进去,如果可以的话,返回 True 并且 switch 进去,否则返回 False

20、invisibilityOfElementLocated(final By locator)

某个元素中是否不存在于dom树或不可见;

21、invisibilityOfElementWithText(final By locator, final String text)

判断带有文本的元素要么不可见,要么文本不存在于元素上

22、elementToBeClickable(final By locator)

判断某个元素中是否可见并且是enable的,这样的话才叫clickable;

23、elementToBeClickable(final WebElement element)

判断某个元素中是否可见并且是enable的,这样的话才叫clickable;

24、stalenessOf(final WebElement element)

判断一个元素是否仍在DOM中,传入WebElement对象,可以判断页面是 否刷新了。

25、refreshed(final ExpectedCondition<T> condition)

26、elementToBeSelected(WebElement element)
页面元素处于被选中状态

27、elementSelectionStateToBe( WebElement element, boolean selected)

判断某个元素的选中状态是否符合预期,传入element

28、elementToBeSelected(By locator)

判断某个元素是否被选中了,一般用在下拉列表;

29、elementSelectionStateToBe(final By locator, final boolean selected)

判断某个元素的选中状态是否符合预期,传入locator

30、alertIsPresent()

判断页面上是否存在alert。

31、not(final ExpectedCondition<?> condition)

32、WebElement findElement(By by, WebDriver driver)

33、List<WebElement> findElements(By by, WebDriver driver)

34、isElementPresent(By.id('xxx')

234567 </div> <link href='https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-258a4616f7.css' rel='stylesheet'> </div>

评论区