david hol
david hol

Reputation: 1280

What ExpectedConditions should i use in order to

So sometimes when i want to click on WebElement i am using elementToBeClickable. Now when i want to get text etc. i have 2 options (maybe more ???) that i usually use:

  1. presenceOfElementLocated - An expectation for checking that an element is present on the DOM of a page.

  2. visibilityOfElementLocated - An expectation for checking that an element is present on the DOM of a page and visible.

My questions:

  1. Whats the different between the both ?
  2. When i want to get text from element/attribute maybe should i use another ExpectedCondition ?

Upvotes: 1

Views: 158

Answers (1)

alecxe
alecxe

Reputation: 473793

presenceOfElementLocated would just wait for the presence of an element in the DOM tree.

visibilityOfElementLocated would not only ensure that an element is present, but also check if the element is displayed. The logic behind the visibility determination is described here:

Which Expected Condition to use is not that simple as in case of elementToBeClickable and a button needed to be clicked - in this case depends on the actual use case - how the desired element is loaded, is it loaded with the text, or the text is set later and dynamically etc.


There is also textToBePresentInElement which might be more suitable, but it requires you to know a part of the element's text.

And, there is always an option to write a custom Expected Condition - for instance, you can wait for any text to be present in element.

Upvotes: 1

Related Questions