Why using waits in selenium?
When a web page is loaded the elements within a page may load at different time intervals, this makes locating element a bit difficult , if element is not present in the DOM it will raise ElementNotVisibleException. To solve these selenium has provides us 2 types of waits
- Implicit wait: This wait is used to tell webdriver to wait for a certain period of time when trying to find the elements if they are not immediately available.
- Explicit wait: This wait is used to tell webdriver wait for a certain condition to occur before proceeding with the code
Implicit Wait
The below code is an example of Implicit wait where the webdriver waits for a fixed 20 seconds before halting the program as the class"aa" does not exist on facebook page
Output
NoSuchElementException |
Explicit Wait
The below code is an example of Explicit wait where the webdriver waits until submit button on the facebook page is visible and clickable.It does not wait for fixed 10 seconds as specified in WebdriverWait(a,10)
Output
0 comments:
Post a Comment