Amith
Amith

Reputation: 7008

performance of visibilityOfElementLocated v/s presenceOfElementLocated (selenium webdriver - Java)

I prefer using visibilitOfElementLocated to locate elements over presenceOfElementLocated. The reason for this is it does the work of presenceOfElementLocated as well (Correct me if i'm wrong).

But there were few situations where i could've achieved my goal just by using presenceOfElementLocated, instead i used visibilityOfElementLocated.

Question :

(or let me rephrase)

Upvotes: 1

Views: 6459

Answers (1)

Petr Mensik
Petr Mensik

Reputation: 27496

Well, I would guess that presenceOfElementLocated will be slighty faster because it's just check elements presence on the page while the visibilityOfElementLocated has to check the presence and whether is element visible.

But I think it really doesn't matter from the performance perspective (what's the point if you save 0.001 second during this checking?), you better choose appropriate method depending on your use case.

  • use presenceOfElementLocated when you don't care whether if element visible or not, you just need to know if it's on the page
  • use visibilityOfElementLocated when you need to find element which should be also visible

Look at the documentation for more info.

Upvotes: 7

Related Questions