This implementation would avoid unnecessary code complexity. It is better to choose the latter one as it involves adding a single line of code rather than adding five to six lines of code in Selenium waits. In such cases, we can use either Fluent waits to suspend the time until the element is visible in the page or use Thread.sleep(). While testing a web page, there is a possibility where the page is loaded, and the execution has moved to the next step, but there wasn’t enough time to select an option in the webpage. Instead of using Selenium waits to check for the visibility of the web element, we can wisely choose Thread.sleep() to wait for a few seconds. For example, most of the eCommerce websites have carousel/slider design which changes dynamically. There might be times where the application’s webpage has dynamic elements and it will be hard to predict the behaviour. Below are some major reasons why we use Thread.sleep() in Selenium Java- Handle Dynamic Elements: Using functions like Thread.sleep() Java enables us to run automated tests successfully without coming across any failure of the script. Thread.sleep() plays a pivotal role in including the page load in our Selenium scripts. With web applications getting bigger by the minute, it is no surprise that different applications take different times to load completely. Why Do We Use Thread.sleep() in Selenium? We will dig deeper into the difference between Thread.sleep() Java & Selenium waits in the next sections.īelow is the syntax for Thread.sleep() Java. And this should not be confused with the Selenium waits mentioned above. This function is particularly helpful for debugging a website or web page. It accepts the time specified in milliseconds. It pauses the execution and helps us to know what has happened during the pause. Thread.sleep() is a static Java method that suspends the code for a specific amount of time. However, there are a few instances where Thread.sleep() would be considered a better choice.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |