Session 27 – Selenium with Java | WebDriver Waiting Met… — Transcript

Learn about Selenium WebDriver wait methods, synchronization problems, and how to handle them using implicit, explicit, and fluent waits in Java.

Key Takeaways

  • Synchronization problems occur when automation scripts run faster than the application response.
  • Thread.sleep is a simple but inefficient way to handle waits and can lead to longer test execution times.
  • Selenium WebDriver provides implicit and explicit waits to handle synchronization more effectively.
  • Explicit wait, including fluent wait, offers more control and flexibility for waiting on specific conditions.
  • Proper use of wait methods reduces exceptions and improves test stability and reliability.

Summary

  • The video explains synchronization problems in Selenium automation testing caused by differences in application response time and script execution speed.
  • It discusses common exceptions like NoSuchElementException and ElementNotFoundException that arise due to synchronization issues.
  • Thread.sleep is introduced as a basic Java method to pause execution but has disadvantages compared to WebDriver wait commands.
  • Selenium WebDriver provides two main wait types: implicit wait and explicit wait, with explicit wait having a variant called fluent wait.
  • Implicit wait applies a default waiting time for the entire WebDriver instance, while explicit wait waits for specific conditions.
  • Fluent wait offers more flexibility by allowing polling intervals and ignoring specific exceptions during the wait.
  • The video emphasizes that controlling application speed is not possible, but controlling script execution speed via waits is essential.
  • Examples are shown using Eclipse IDE to demonstrate the use of Thread.sleep and WebDriver waits in practical scenarios.
  • The video highlights the importance of using wait commands over Thread.sleep for efficient and reliable test automation.
  • It also covers the advantages and disadvantages of each wait method and when to use them.

Full Transcript — Download SRT & Markdown

00:02
Speaker A
Right, so in the previous class, we have seen get methods, and also we have seen how to use conditional methods and then browser methods like close and quit. So today, we'll discuss about wait commands, or we can say wait methods, which are provided in Selenium. So first of all, why do we need to use the wait command? So before that, we need to understand what is synchronization problem. So almost in every automation tool, we face this problem, synchronize or synchronization problem. So what is synchronization? Sometimes what happens is when you run your automation test script, and parallel your application also should interact or should invoke the application, and it shows all the elements of the web page, right? So when you run your automation test scripts, at the same time the web page and elements should be available, and then only your automation test script will be able to perform the actions on the web elements. But sometimes what happens is maybe some application is not available by the time script is executing, and suppose some element is not available, then you will get some kind of exception like no such element exception, element not found exception. So such type of exceptions you will get. So that is called synchronization problem. So what is the main root cause for this? It is speed of your application, like execution speed is faster or the speed of your automation script is faster than your application response. So that will cause the synchronization problem. Almost in every automation tool, we can see this kind of problem. Okay, so let me give you some example. Let's say I have few lines of code I have written like this. Okay, and let us say this will launch our application. This is our application under test. So let us say I want to execute this particular step. Now on this particular element, to execute this particular step, I need some element on this page. Okay, or suppose sometimes what happens is I want to execute this step, but for this particular step, I need another web page. I need to navigate to another web page. So what will happen is by the time the statement is got executed, maybe the element is not available or the web page is not fully loaded. In those cases, what happens? This statement will throw exception, and because of this, we got synchronization problem. So this is called synchronization problem. So speed of your application is very slow, and your execution is faster than your speed of your application or the response of your application. That is called synchronization problem. So in that particular situation, we will get synchronization problem. Then how to solve this problem? So to solve the problem, what we can do is the application response is not in our hand because we cannot control the speed of your application because it depends on many factors. Like suppose sometimes your network speed is very slow, then your application will respond very slowly. And sometimes many people are accessing the same application, same page at the same time. In that case also, your application response will be slow. So there are multiple factors involved. So we cannot control the speed of your application. The only thing is we can control the execution speed of your automation test script. So this is in your hand. You can control this, but you cannot control your application. So what we can do is suppose there is a statement here, and to execute the statement, we need some element. So what we can do is while executing the statement, we can wait for this element, or we can pause your script for some time here, and once the element is available, then we can resume the execution, right? So this way we can handle this. And by default, we have one Sleep method in Java, thread.sleep. So wherever you can see this kind of a problem, you can put thread.sleep. So this is a normal method. We have used earlier also wherever the sync problem occurs, and wherever the page is taking more time to load or more time to display the element, we put this thread.sleep, and we put some time in the milliseconds, and then our script is paused for some time, and meanwhile the element is available, then it will go and execute the rest of the statements. But other than this, WebDriver itself is provided some of the wait commands. By using those wait commands, we can solve synchronization problem, and most of the times we will prefer to use wait commands instead of thread.sleep command. And thread.sleep is having some disadvantages. We will see what are the disadvantages, and then we will discuss other commands provided by Selenium WebDriver. And every wait statement has its own advantages and disadvantages, but WebDriver wait commands, like whatever waits are provided by WebDriver, they will work more efficiently than thread.sleep. Okay, so how many ways we can handle synchronization problem? So thread.sleep is actually not coming from WebDriver, which is Java method itself. It is coming from Java itself. So this is not a WebDriver command, remember this. Okay, if anybody asks you what are the wait methods provided in Selenium, there are only two kinds of waits provided. One is called implicit wait, second is explicit wait. Okay, implicit wait and explicit wait. So these are the only two wait statements provided in Selenium. And in explicit wait, again we have another flavor of wait which is called fluent wait. This is also explicit wait, but it will provide some more options than explicit wait. These are the only two wait commands provided by Selenium WebDriver. Thread.sleep also we can use, but this is not related to Selenium WebDriver. So Java itself is provided thread.sleep command. Okay, and implicit wait and explicit waits are provided by Selenium WebDriver. So these are the only two types of wait provided by Selenium WebDriver. In explicit wait, we have another flavor called fluent wait. Okay, now we'll discuss one by one. First, we'll start with the Sleep command. So what is the advantage and what is the disadvantage of sleep command? So before that, let me show you an example where we will try to use sleep command. Okay, go to Eclipse and create new package day 27. First thing, sleep command. Okay, so now let me write a small piece of code. Okay, now I have written this piece of code, and I'll import all the classes and everything, and this is thread.sleep. So if I don't put this here, what will happen is it will launch your application, and after that, I'm interacting with some element here. So if I open this particular web page, you can see login screen. So this is your login screen, and here there are some elements. So here I have, I'm interacting with this username input box, and I'm passing some value here through XPath. I have interacted with that element, and then I have passed some value. So I have not used sleep command for now. So we'll see what is a problem with this when I run as a Java application. So synchronization problem you may not get every time. Okay, so randomly depends upon the scenario, you will get it. But whenever you get a synchronization problem, then you can handle it. Even if you're having suppose doubt about synchronization, suppose you are guessing it sometimes. So in that case also, you can keep the synchronization part. Now you can see here application is launched, and it is waiting cursor here, but still the value is not entered in this box. And if you go back and see, you'll get this exception no such element exception. Okay, so there are two kinds of exceptions you have to notice here, most important. Sometimes in interview also will ask no such element exception. That is one type of exception, element not found exception. These are the two types of exceptions most of the time you can see. So when will you get no such element exception? When will you get element not found exception? Can anyone guess? No such element exception and element not found except...
00:27
Speaker A
why we need to use uh the weight command so before that need to understand so what is synchronization problem so almost in every automation Tool uh we face this problem synchronize or synchronization problem so what is synchronization so sometimes what happens is when you run your
00:52
Speaker A
automation test script and uh parall your application also should interact or should uh invoke the application and it show all the elements of the web page right so when you run your automation test scripts at the same time the web page and elements should be
01:10
Speaker A
available and then only your automation test script will able to perform the actions on the web elements but sometimes what happens is uh maybe some application is not available by the time script is executing and suppose some element is not available then uh you will get
01:29
Speaker A
some kind of exception like no such element exception element not found exception so such type of exceptions you will get so that is called synchronization problem so what is the main root cause for this is speed of your application like execution speed is faster or
01:48
Speaker A
the speed of your automation script is faster than your application response so that will cause the synchronization problem almost in every automation Tool uh we can see this kind of problem okay so let me give you some example let's say I have few lines of code I have written like
02:06
Speaker A
this okay and let us say this will launch our application this is our application under test so let us say I want to execute this particular step now on this particular element so to execute this particular step I need some element on this page okay or suppose sometimes what happens is I
02:28
Speaker A
want to execute this step but for this particular step I need another web page I need to navigate to another web page so what will happen is by the time the statement is got executed maybe the element is not available or the web page is not fully loaded in those cases what happens this
02:49
Speaker A
statement will throw exception and because of this we got synchronization problem so this is called synchronization problem so speed of your application is very is slow and your execution is faster than your speed of your application or the response your application
03:08
Speaker A
that is called synchronization problem so in that particular situation we will get synchronization problem then how to solve this problem so to solve the problem what we can do is the application response is not in our hand because we cannot control the speed of your application
03:27
Speaker A
because it depends on many factors like suppose sometimes your network speed is very slow then your application will respond very slowly and sometimes many people are accessing the same application same page at the same time in that case also your application response will be slow
03:46
Speaker A
so there are multiple factors are involved so we cannot uh control the speed of your application only thing is we can control the execution speed of your automation test script so this is your in in your head you can control this but you cannot control your application so what we
04:06
Speaker A
can do is suppose there is a statement here and to execute the statement we need some element so what we can do is while executing the statement we can wait for this element or we can pass your script for some time here and once the element is available then we can resume the execution right
04:26
Speaker A
so this way we can handle this and uh by default we have one Sleep Method in Java thread. sleep so wherever you can see this kind of a problem you can put thread do sleep so this is normal method
04:40
Speaker A
we have used earlier also wherever the synchron problem is occur and wherever the page is taking more time to load or more time to display the element we put this thread dot sleep and we put some time in the milliseconds and then our script is passed for some time and uh meanwhile
04:59
Speaker A
the element is available then it will go and execute the rest of the statements but other than this web driver is itself is provided some of the weight commands by using those weight commands we can solve synchronization problem and most of the times we will prefer to use weight commands
05:19
Speaker A
instead of thread. sleep command and thread do sleep is having some disadvantages we will see what are the disadvantages and then we will discuss other command provided by selenium web driver and every weight statement is having some its own advantages and deserve advantages but uh
05:40
Speaker A
web driver weight commands like whatever weights are provided by web driver they will work more efficiently than thread do sleeper okay so how many ways we can handle synchronization problem so thread do sleep is thread do sleep is actually not coming from web driver
06:07
Speaker A
which is Java method itself it is coming from java itself so this is not a web web driver command remember this okay if anybody ask you what are the weight methods are provided in selenium there are only two kinds of Weights are provided one is called implicit weit second is
06:31
Speaker A
explicit weight okay implicit weight and explicit weight so these are the only two weight statements are provided in selenium and in explicit weight again we have another flavor of weight which is called fluent weight this is also explicit weight but it will provide some more options uh than
06:51
Speaker A
explicit weight these are the only two weight commands provided by selum web driver thread do sleep also we can use but this is not related to sing a web driver so Java itself is provided thread. Ste command okay and implicit weight and explicit weights are provided by selenium web
07:10
Speaker A
driver so these are the only two types of weight provided by selenium web driver in explicit weight we have another flavor called fluent weight okay now we'll discuss one by one first we'll start with the Sleep command so what is the advantage and what is the disadvantage of sleep comand so
07:29
Speaker A
before that let me show you an example where we will try to use sleep command okay go to eclipse and create new package day 27 first thing sleep command okay so now uh let me write a small piece of
08:06
Speaker A
code okay now I have written this space of code and uh I'll import it all the classes and everything and this is thread do SLE so if I don't put this here uh what will happen is it will launch your application and after that I'm interacting
08:31
Speaker A
with some element here so if I open this particular web page you can see login screen so this is your login screen and here there are some elements so here I have uh I'm interacting with this username input box and I'm passing some value here through X paath I
08:52
Speaker A
have interacted with that element and then I have passed some value so I have not used slep command for now so we'll see see what is a problem with this when I run as a Java application so synchronization problem you may not get every time okay so randomly depends upon the scenario
09:09
Speaker A
you will get it but whenever you get a snation problem then you can handle it even if you're having suppose doubt about synchronization suppose you are guessing it sometimes so in that case also you can keep the synchronization part now you can see here application is launched
09:28
Speaker A
and uh it is waiting cursor here but still the value is not entered in this box and if you go back and see you'll get this exception no such element exception okay so there are two kinds of exceptions you have to notice here most important sometimes in interview also will
09:48
Speaker A
ask no such element exception that is one type of exception element not found exception these are the two types of exceptions most of the time you can see so when you will get no such element exception when you will get element not found exception can anyone guess no such element
10:10
Speaker A
exception and element not found exception so element not found exception you will get whenever your locator is not matching with the element your locator is not correct locator is incorrect okay locator is incorrect in such case you will get a element not found exception
10:40
Speaker A
if the locator is incorrect then you will get element not found exception and no such element exception you will get when you have a synchron problem your locator is correct but by the time the statement is got executed the element is not available on the web page Okay so so when
11:00
Speaker A
the element is not present not present on the page then you'll get this exception and this is basically synchronization problem okay so no such element exception so whenever you get this kind of exception you can easily understand which is basically because of synchronization
11:23
Speaker A
problem and element not F exception you will get when you're are using element is available on the web page but you are using some incorrect locator incorrect Expo or incorrect CSS in that case you will get element not found exception most of the times okay so whenever you see no
11:42
Speaker A
such element exception you can easily decide or you can easily find out that is a synchronization problem because of synchronization problem okay so now if I look at this as it is launching my page but after that the statement is not executed and it is clearly saying no no such element exception
12:01
Speaker A
if you look at here which element it is this is a element it is talking about element also it's clearly show the element also so this is uh exception we got because this element is not available it is not able to find that element so we got this exception no such element exception
12:23
Speaker A
because of synchron problem we got the problem so now I put this thread dot sleep here just wait for some few seconds thread do sleep will uh we pass your execution here for some time after launching the page our script execution will pass here for some time or 3 seconds and
12:42
Speaker A
meanwhile the elements are available so after that if you execute the statement it will execute successfully let me try to execute now so I will close this and run as Java application just observe here it is launching the page after 3 seconds it is trying to enter the
13:09
Speaker A
value so when it put sleep command it is able to solve the problem so we haven't get exception still the statement is successfully executed but what is the problem it is able to solve the signation problem right it is able to solve it but what is an advantage and what is a
13:28
Speaker A
disadvantage of this sleep command okay let me write here few points about sleep command so the advantage of sleep is easy to use you can easily use it right just simply say thread. sleep and we can put some time so wherever you find syation problem in
13:56
Speaker A
your automation script you can simply add this method so that will solve the syation problem very simple to use and very easy to remember also but what are the disadvantage of this if the time is not sufficient then you will get an exception suppose I put three 3,000 milliseconds here that
14:19
Speaker A
means 3 seconds suppose if it is taking more than 3 seconds to display that element okay if this element is displayed or if this element is visible within 3 seconds no issues it will solve the snation problem but suppose if this element is taking more than 3 seconds still there is a
14:40
Speaker A
chance of getting an exception because this value we have hardcoded so sometimes it may take more time right so in that case we will get a CH we have a chance of getting an exception second problem is suppose here 3 seconds I put here and this element is taken just only one 1 second then
15:02
Speaker A
other two seconds will be wasted here even though the element is available on the web page within 1 second still it will wait for 3 seconds because until unless this time is completed it will not go to the next statement even though this element is available it will not go to the next statement and
15:21
Speaker A
execute because once this time is over then only it will go and execute the next statement Okay so if you put thread do sleep 5 seconds if the element is not available within two or 3 seconds the rest of the time will be wasted and thread do sleep if I use multiple places in many places
15:41
Speaker A
in your Automation skript and multiple times in every place it will wait for 3 seconds and it will wait for 5 seconds depends upon the time you specified so it will be wasting of time so obviously your performance of your automation test script will be reduced this will cause
15:59
Speaker A
a poor performance of your automation script if you have a huge number of automation scripts and many places if I you thread. obviously that will reduce the performance of your automation test script so if the time is more than this still there is a chance of exception if the element
16:18
Speaker A
is taking less time in that case also it will cause the poor performance of your automation test in the both the ways we have a disadvantage so these are the two disadvantages if the time is not sufficient then again you will get a exception and it will wait for maximum time out so that
16:41
Speaker A
is the reason it will reduce the performance of your automation script so even though element is available within one or two seconds still it will not go and execute the statement once the time is over then go and execute the statement right so this is the second disant it will wait for maximum
16:59
Speaker A
time out how much time is specified it will wait for maximum Time Out and because of this it will reduce the performance of your script and third thing is what multiple times we need to write suppose you have a five places you're facing snation problem and you you want to deal with
17:16
Speaker A
five to six different pages you want to navigate so in every place you need to write thread do sleep multiple times you have to write wherever the snation problem is occurring you have to add thre dot sleep multiple times so this is another problem okay so because of this we are not going
17:35
Speaker A
to use the do sleep most of the times we never prefer the do sleep command as a beginner in the initial stage while learning the concepts you can still use it but once you designer automation or once you are working on automation projects we should avoid thread dot sleeve command this
17:56
Speaker A
is not at all recommended it is is just easy to use but there are disadvantages because we put hardcode a time here and sometimes elements may take more time or elements take very less time if the element is taking more time still there is a chance of getting an exception if the element
18:15
Speaker A
is taking less time still there is a chance of having poor performance of your automation skip because in every place in every weight it every sleep command it will wait for maximum time out even though the elements are available still it will not executed it will still wait for
18:30
Speaker A
some more time and then catch the so because of these disadvantages we never use thre do sleep it will not be preferable and this is not web driver command this is Java command itself and many people will combine this with implicit and explicit weight and finally they tell three
18:50
Speaker A
types of Weights actually there are only two types of Weights selia web driver is supported thread door sleep is just a method which is provided by Java itself it is not comes under weight statement of selenia web driver okay if anybody ask an interview you should be very very clear about
19:09
Speaker A
this comp all right so everyone is clear about thread do sleep what are the disadvantages of this right so now let us move on to the actual weight statements provided by selenium web driver so web driver is provided two weight statements implicit
19:32
Speaker A
weight and explicit weight so we will talk about implicit weight first so it's very very simple implicit weight so how to use implicit weight let me create another example same example this time I will try to use implicit
19:53
Speaker A
weight impit weight demo so don't write only implicit weight okay just add some more stuff like this implicit weight demo and the same example I'm taking this time instead of sleep command I will try to use implicit weight so let's remove this okay now this code will give you no such element
20:18
Speaker A
exception because of synchronization problem so if you want to use implicit weight in your automation test script as soon as you created your driver instance you can access one method here driver dot manage dot inside this manage there is a method called timeouts and again inside the
20:42
Speaker A
timeouts we have to call implicitly weight so this is a method actual method implicit weight method so this we have to call from driver object the driver we have to first call manage that will return options object from from the options we have to call timeouts that will return return
21:01
Speaker A
timeouts object from the timeouts we have to call implicit weight so here we have to pass time right every weight statement is required time so here we have to pass some time so how to pass the time so
21:17
Speaker A
to pass the time we can simply use a special class called duration class and inside this there is a different type of methods are there so if you can specify time in seconds milliseconds minutes hours and whichever format you want to specify you can specify most of the times we specify in seconds so
21:40
Speaker A
duration dot of seconds you can take this method and you can put maximum how much time you want to specify you can say 5 seconds and then semicolon this is called implicit weight method implicit weight okay and one thing you need to notice here we are getting synchronization problem after
22:05
Speaker A
launching the page when you getting this element you are getting syation right but why we need to put this implicit weight at the beginning of the script right so the reason is how exactly implicit weight works so when you put this implicit way is always only one single statement suppose
22:29
Speaker A
you have a five different places you are getting snation problem you no need to write this implicit way to five times only one time you have to write and when you have to write after creating the driver instance okay so how this is going to work so this implicit weight is applicable
22:48
Speaker A
for every statement in your automation script if you have 100 lines of code and this particular implicit weight is applicable for all 100 lines of code and wherever the synchronization problem is occurred the implicit weight will take care of it the implicit weight will wait for maximum
23:08
Speaker A
5 seconds for the element or for the page and that will automatically solve the synchronization problem so the advantage of this implicit weight is we can just specify only one time before after creating the driver instance only one time and this particular implicit weight is applicable for
23:29
Speaker A
all the statements in your automation script and this is alive till you close your driver okay so when you will close your driver at the end of the automation script you will close or you will quit from the driver so till you close your driver this impit weight is alive or it is active and
23:49
Speaker A
it is applicable for all the statements in your automation test script okay so the advantages are what we can put only one time we don't need to write multiple times and second thing is what you no need to uh predict the scenario like you know need to know where exactly you're getting
24:12
Speaker A
synchronization problem so wherever the synchron problem is occurred in whichever statement is throwing exception because of synchronisation problem the same implicit weight will take care of it okay suppose if this is taking some time implicit weight take care if this element is
24:29
Speaker A
taking some more time then again implicit weight time will take care so all kinds of uh signation problems will take care of one statement Take Care by one single statement okay these are all advantages but we also specifying the time here right but because of this will it cause any poor
24:55
Speaker A
performance like thread door sleep because if if I want to use implicit weight we should have some advantages when you compare with the thread dot sleep right so what are the advantage of it when you compare with the thread dot sleep what is an advantage here see the major difference is
25:15
Speaker A
in thread dot sleep whatever the time is specified once the time is over then only the next statement will execute okay after 3 seconds suppose if you put three 3 seconds or 5 seconds or 10 seconds so once the cut off time is over then only the next statement will execute even though that element
25:38
Speaker A
is available within few seconds right this is a behavior of thread do sleeper suppose here 5 seconds I put here but element is available within two seconds this element is available within two seconds but still it will not execute after completion of 5 Seconds only the next
25:56
Speaker A
statement will execute because of that Reon it is causing the poor performance but when you come to implicit weight this is actually maximum time out suppose if this element is available within two seconds then it will execute automatically it will not wait for maximum time out because we put
26:15
Speaker A
5 Seconds here 5 seconds is what maximum time out so if this element is not available how much time it will wait 5 Seconds it will wait suppose if the element is available within 2 seconds so this will not wait for another 3 seconds it will go and execute the next statement
26:34
Speaker A
immediately so there is no problem of performance issues here that is one big Advantage when you compare with the thread dot sleep but there is one problem still what is the problem we have in this because of this time if the element is taking more than five 5 Seconds still there
27:00
Speaker A
is a chance of getting an exception right because we are hardcoding the time here whenever you hard coding time definitely that limitation will be there so sometimes if the element or if the page is taking more than 5 Seconds how much time this implicit weight can wait implicit
27:17
Speaker A
weight can wait maximum 5 seconds and after 5 seconds if this element is available still it will throw exception no such element exception okay so that's how this implicit weight will work so the default time of implicit weight is what default time is zero only it will not wait for
27:39
Speaker A
Maxum time so default time is zero but if any element is not available of any page is still not available it will wait for maximum 5 seconds for that element for that particular page and then it will proceed with the rest of the statements so that's how this implicit weight will work so
27:56
Speaker A
even though we put this in the beginning it will applicable for all the commands throughout your automation because we are referring the driver right until this driver is alive this implicit weight is applicable for all the statement it doesn't mean every statement it will wait for
28:17
Speaker A
5 seconds no okay what I'm saying just carefully you need to understand what is my point here is this driver. manage. timeout. implicit weight is implicit weight statement what I'm saying this is applicable for all the commands all the statements in your automation script it
28:36
Speaker A
doesn't mean for every statement it will wait for 5 seconds no when it will wait for 5 seconds for that par statement if that element is not present on the web page or if the element is not available
28:48
Speaker A
still not loaded on the web page then only the 5 Seconds will be consider maximum 5 Seconds it will wait if the element is available then it will go and execute the statement as usual okay it will not unnecessarily waste the time so you need to understand the difference it is applicable for
29:07
Speaker A
all the commands all the statements But whichever statement is taking more time to load on the web page the 5 Seconds will wait for that particular statement and if element is available immediately it will jump to the next statement so that's how implicit weight Works let's try to execute this
29:28
Speaker A
code but still there is a problem with the simplicit weight what is the problem see it is successfully executed and also my browser is got closed I haven't used thread do sleep but still this implicit we statement is taking care of it okay but there is one
29:55
Speaker A
common disadvantage in thread door sleep and implicit weight what is the problem the time right if the element is taking any statement or any element is taking more than 5 Seconds still there is a chance of getting a exception no such element exception okay
30:15
Speaker A
so now let me write some notes Here related to so we understood sleep command advantage and disadvantages now when you come to implicit weight what are the advantages and disadvantages so this is implicit weight syntax driver. manage. timeouts and implicitly wait duration of seconds
30:43
Speaker A
and you can put any number of seconds there is no limit for this maximum 10 seconds are preferable okay if any element or any web page is taking more than 10 seconds that is causing a performance issues okay uh report performance issues on that application so Standard time is maximum 10 seconds
31:05
Speaker A
it should not exit maximum 10 seconds right so what is an advantage of this implicit weight only single time or one time we can specify this you don't need to write multiple places in multiple times only one time you have to write implicit weight and it will not wait till maximum
31:25
Speaker A
time if the element is available this is a major difference difference between sleep and implicit weight in the Sleep command what will happen even though the element is available still it will wait for maximum time and then it will proceed but in implicit weight it will not wait for element it
31:43
Speaker A
will just wait how much time it is required and then it will proceed further so it will not cause performance issues that's the second Point third point is what applicable for all the elements you don't need to worry about where exactly you will get synr problem you don't need to worry
31:58
Speaker A
about it so once you put this simplicit weight in one place that is taking care of all kinds of synchronization problem wherever you are getting third fourth point is one it is very easy to use because a single statement right driver. manage so you will understand once you understand fluent
32:15
Speaker A
weight and explicit weight how much easy it is you will understand when you compare with explicit or fluent weights it is very simpler than that one so implicit weight is very very easy to use and again what is the disadvantage of this if the time is not sufficient then uh you will still have chance
32:35
Speaker A
of getting exception this is a disadvantage but maximum 10 seconds you will specify and uh you will never expect any exceptions most of the times if your application performance is very good right so then maximum 10 seconds is more than enough even it is element or if it is a web page it
32:55
Speaker A
should be loaded it should be available Within in 10 seconds that's a maximum Standard Time okay if it is taking more than 10 seconds you can easily rep as a performance issues okay so this is all about implicit pait so is this clear everyone advantages and disadvantages you have to remember
33:18
Speaker A
these points because during the interview people will ask you so what are the weight statements are available what is the differences what is the advantage what is the legit advantages right so once we discussed all uh weight statements then we will see which one we will prefer and why we
33:38
Speaker A
need to prefer all those things now let us move on to the next weight statement which is explicit weight explicit wait okay so implicit weight and thread dot sleep in both ways we majorly we will consider the time right how much time we have to wait for the element so that will play most important role but
34:16
Speaker A
when you come to thread or when you come to the explicit or fluent weights before considering the time we have to put certain condition so it will consider two things actually one is condition the second one is time but in the sleep and implicit weight we will consider
34:35
Speaker A
only time but when you come to explicit or fluent weights we will consider the condition we have to put certain condition and then we'll consider the time so how exactly explicit work explicit weight Works in explicit weight we will specify the time also but we will see what is the time we specify
34:57
Speaker A
before that is most important first let me show you the Practical example and after that we will try to understand the syntax and everything so let me create another example for explicit weight and every time you may not get exceptions so but whenever you see the exceptions and then
35:27
Speaker A
you can try to use them just to understand how to use it okay explicit weight so I'll try to remove this implicit weight for now okay so how to use explicit weight and what is a syntax of this so if you want to use explicit weight there are uh
35:51
Speaker A
two steps one is declaration the second step is usage okay first we need to declare the explicit weight once it is declared then we can use it so there are two things are there declaration how to declare explicit weight and after that how to use explicit weight for the
36:17
Speaker A
particular element and uh it's not like implicit weight okay implicit weight once you write one single statement this is applicable for all the statements for all the elements in your autom test script but explicit weight is not like that explicit weight is for specific to element
36:37
Speaker A
specific to web element or specific to web page so we can put certain condition and explicit vo Works based on the condition and then it will consider as a Time condition is most important okay now go back to the example so how to declare explicit weight as I said two
36:58
Speaker A
steps one is declaration other one is usage so how to declare explicit weight so to declare explicit weight once you created your driver instance here you have to use a special class called Web driver weight class web driver weight it is another class which is already there in your selenium
37:21
Speaker A
web driver for that we need to create one object let's say I call this my weight equal to new web driver weight so we need to create an object for web driver weight so that we need to import from
37:39
Speaker A
theop gear. selenium dos support. and inside this web driver weight class there is a Constructor so that will expect two parameters one is the driver we have to pass as a first parameter second parameter we have to spe specify the time also so how to specify the time just like in
38:02
Speaker A
implicit weight we use duration class right same thing here duration dot of seconds of you can put maximum five or 10 whatever you want maximum 10 seconds so this is called declaration part we just only declared still we haven't uh applied this explicit fade for the elements or for the PTI
38:28
Speaker A
is just declaration still it will not applicable just only with the Declaration we can we cannot avoid syation problem still you will get exception so this is only declaration now whichever element is thring exception or causing synchronization problem we need to identify that element okay
38:51
Speaker A
so in this particular example this particular element is throwing exception so because because after launching the page when you finding this element when you are finding this element you are getting no such element exception because this particular statement or this particular
39:07
Speaker A
element is taking some time to load on the web page right so once you identify then we should apply this web driver weight object or we should apply this explicit weight on this particular element we should apply explicit weight only on that particular element so how to
39:30
Speaker A
apply so let me show you so let's comment this so now application how to apply this explicit weight on this element so to apply this we have to take the help of this my weight object my weight Dot
39:52
Speaker A
and uh as I said one point here explicit weight Works based on the condition after that only it will take consideration of time so first it will work on the condition so the condition we have to specify using until method my weight do until in this we have to specify the condition so how
40:14
Speaker A
can we specify the condition again we have to use another class expected conditions dot here it will show you all the conditions so whichever condition is relevant to that element you can choose that condition suppose what is my condition here is I just want to wait for the element visibility that
40:36
Speaker A
element should be visible on the web page that's my condition so you can take one method from this visibility of okay so you can find so many methods you can choose whichever method is relevant to your scenario visibility of element located I'm taking this method visibility of element located
40:57
Speaker A
and which element this one only the locator part you have to specify only locator part you have to pass here okay now what will happen in this statement is just observe very carefully my weit do until expected conditions do visibility of element located by. xath of this element so when
41:23
Speaker A
you put this statement and then uh you can end of the statement so how this statement is going to work okay let's try to minimize this so that the entire statement you can see so you need to understand the whole
41:40
Speaker A
statement okay so just observe how exactly the statement works so this is a locator part right so this is just a locator this part is called locator and my weight is a actual implicit weight or explicit weight object my weight do until is a method through which we can put the
42:06
Speaker A
condition my way. until and this is representing the condition what is a condition we selected here there are number of conditions are there in this expected conditions class so what is the condition we have chosen here is visibility of element located so visibility of element
42:22
Speaker A
located which element this is the element this is representing the element so this particular statement will wait until this element is visible or until this element is located on the web page so once it is visible then this particular condition becomes true so once this uh element
42:46
Speaker A
is visible on the web page then the condition until method becomes true whenever this until method returns true that will return the web element so that we need to store in a variable like this so there are multiple things will happen in one single statement so this is the locator we
43:06
Speaker A
are passing and uh expected condition visibility of located means what this method will wait till this condition becomes true when this condition becomes true if this element is located then the condition becomes true so once the condition becomes true it will return the web element
43:26
Speaker A
for us if it Returns the web element so that we need to specify so here I will create one variable called Web element user or you can say txt username and then web element we have to import okay so this is a whole statement explicit weight now you need to understand something here
43:54
Speaker A
when I use explicit weight statement locating the element or identifying the element is inclusive see here it is locating the element also okay and it is ring the web element so again do we need to write the statement driver. find element is it required because explicit weight itself is
44:21
Speaker A
written the element once it is available on the web page right so once the element is available on the web page the condition becomes true that itself is returning the web element for us so again do we really need to write the statement d. find element x. by do exp all these things
44:41
Speaker A
not needed so you can simply remove this command and try to get this element and Dot send Keys you can directly write like this so whenever you are using explicit weight or fluent weight it will also return the web element directly that means identification of web element is
45:03
Speaker A
inclusive in explicit weights identification of web element is inclusive so you don't need to write a separate method driver. find element when I use explicit weights you don't need to write driver. find element method separately why because the explicit
45:20
Speaker A
weight itself will return the element that we are going to access directly okay so here my weight is what web driver weight object until is a method we can use it for specifying the condition and inside this method how can we put the condition using expected conditions
45:41
Speaker A
class when you say expected conditions dot you can find different type of methods you have to choose the right method which is appropriate in that particular scenario dot I will show you different conditions okay here this is one type of method I have used visibility of element located
45:57
Speaker A
and the locator part and after that it will return the element and we pass the value same thing is appli for password element also suppose if we want to apply uh the same weight statement for password element you can write one more and you can say txt password and here the same condition
46:21
Speaker A
again I can put visible T element located and uh what is an xath of this element you can capture inspect and this is xath of this element go back and xath here this we have to change okay so this is a condition so now we will get the password and once you get the password
46:53
Speaker A
element can pass the admin now after that I want to interact with some other element so let us say I want to click on the login element so let us inspect this login and this is element so how
47:08
Speaker A
can we put explicit weight for this element and what type of condition is suitable for this my weit DOT until and uh expected conditions expected conditions and uh my I can choose here so suppose the this is a button right so we want to perform click action on the button so for what we have to
47:37
Speaker A
wait here till the element is clickable you can also put element is visible condition no problem but even though sometimes element is visible you are not able to click on that element so what is your condition here the element should be clickable so I can choose that conditions
47:55
Speaker A
expected conditions Dot and I can use this me element element to be clickable element to be clickable and here I can just pass the locator of this element so this is a locator of this element even find element is not at all required and in the double course I can just pass this element
48:19
Speaker A
so once it is able to uh once it is visible and clickable then it will return the element that I can store in a variable web element login button and after that you can perform the action login bdn dot click that's it okay so this is element specific so that is the reason explicit weight
48:46
Speaker A
we need to apply not required for every element okay so here just for your understanding I have used multiple times for every element but normally we do not apply explicit wait for every type of element wherever you are getting syation problem whichever element is causing synchron problem for
49:05
Speaker A
that element only we will add this explicit weight other elements not needed other elements you can directly use d. find element it can proceed further okay I think one more bracket is required element to be clickable sorry we forgot to buy do specify by.
49:35
Speaker A
xath okay one more bracket so this is how we can put and then after that you can put and few things you need to remember this explicit weight Works based on the condition so if this condition is true then only it will return element here if this condition is true element to be clickable
50:02
Speaker A
then only it will return the element otherwise will not okay and uh it is basically waiting for what element element should be visible or element should be clickable or element should be available on the page so these are different conditions and explicit weight is basically
50:21
Speaker A
waiting for the element so once the element is available that will return the web element okay but if it is working based on the condition where this time comes into picture because we specify some time right in the explicit weight but where this time will be considered if you
50:42
Speaker A
look at these statements it seems like it works based on the condition which we specified it is waiting for the element waiting for element to be clickable waiting for visibility of element located but when the this time will be considered okay let me give you simple example
51:03
Speaker A
based on that you can understand how exactly this explicit weight works first it will consider the condition and then it will consider the time okay see uh this with this example you can easily understand how exactly explicit weight work let us say there are two friends they have
51:21
Speaker A
to come from two different places and they want to meet at one place exactly 5:00 p.m.
51:27
Speaker A
okay let's say 5:00 p.m. in one particular place they wanted to meet and the two friends should come from two different places and here they wanted to meet exactly sh at 5:00 p.m. now the first friend exactly came here shate 5:00 p.m. here and he is here okay now the second one is
51:48
Speaker A
not still come so he is waiting for his friend to come right he is waiting for his friend to come but 5:00 p.m. shortly 500 p.m. he's available here but he reached here but he's waiting for his friend to come that is called condition so this guy is waiting for what his friend to be
52:14
Speaker A
arrived that's called condition how much time he should wait how much time he should wait 10 minutes 30 minutes 1 hour Hour 2 hours how much time we can wait maximum 10 to 15 minutes right so they decided exactly sharply 5:00 p.m. if this guy is not coming here between 10 to 15 minutes
52:42
Speaker A
maximum 15 minutes he can wait after 15 minutes if he's waiting for 1 hour two hours doesn't make any sense no right if this guy is not coming within 10 to 15 second or 15 minutes there is some problem
52:57
Speaker A
with this so maybe he is facing some issues and because of that reason he's not able to come right so he has he is basically waiting for his friend that is called condition and how much maximum time he can wait that is called the timeout which we specified in the we wait that means first
53:22
Speaker A
it will give the importance to the condition if the condition is true if element is visible or if the element is clickable it will return the web element and if the element is not visible or if it still not element is not available in the web page how much time it will wait for the
53:40
Speaker A
element maximum 10 seconds it will wait that is called cut off time so in explicit wait the first priority will be given to the condition and uh if the condition is still not satisfied Max maimum 10 seconds cut of time we can specify we can it will wait for 10 seconds we can also specify more time
54:05
Speaker A
but Standard time is 10 seconds only okay so explicit weight Works based on the condition if the condition is not satisfied then it will wait for the time 10 seconds within 10 seconds the condition should be satisfied then it will return return the element in some cases even though the
54:27
Speaker A
element is not able to locate within 10 seconds it is taking more than 10 seconds still there is a chance of getting an exception so in almost in every weight statement we will have choice we will have a chance of getting an exception if it is exceeded the specified time so we have to use
54:49
Speaker A
TR catch block that's the only solution for this okay if this statement is not find the element and within this time definitely that will not able to return return element so we need to exit at certain point of time right we cannot wait for 15 minutes or 30 minutes for the element if this
55:10
Speaker A
element is not visible in 10 seconds it will exit from the statement and thr the exception so that problem still be there but 10 seconds is a maximum time out but when you compare with the implicit weight this will work more effectively because here we are waiting for the element we not
55:28
Speaker A
totally depends on the time we are depending on the condition okay so this is how explicit weight works okay so we can use find element method there is no restriction yes when I use explicit way suppose if you are preferring to use explicit weight and
55:52
Speaker A
you don't need to use find element method that is not at all needed why because this itself is returning the web element for you right it is itself is by using this locator the explicit weight itself is locating the element and returning it so why we need to
56:09
Speaker A
write another find element it's not needed But whichever element you are not using explicit weight there you can use normal driver. find element method for example this is taking time so here you can use this explicit weight and rest of the elements you can normally use driver. find
56:31
Speaker A
okay so do we have to write for every exception web element this is major disadvantage we no need to apply this weight for every statement that's the reason I'm saying this is just a declaration but how whether you want to apply this weight
56:48
Speaker A
for the element or not depends on the synchronization problem you don't apply this for every web element whichever element is proving exception whichever element is taking synchronization problem you will apply this only for that applic for that element not for every
57:04
Speaker A
element okay so the default timeout for all kinds of weight is zero it will wait for just zero seconds and it will go forther but there is no advantages so we need to specify some time here okay so this is how we you can use explicit weight so let me try to execute clear
57:31
Speaker A
this the password is admin 1 2 3 yeah and the condition methods will be changed it depends upon the different type of elements you have to put a different type of conditions okay now we can see even explicit weight also solve
57:59
Speaker A
the problem and uh we will use a different type of conditions I will put these conditions here just sample conditions uh you can just remember few of them so these are the most popular so alerts present element selection state to be element to be clickable element to be selected and sometimes
58:21
Speaker A
when you're working with the frames you can also use frame to be available and switch to it inis visibility of element located this opposite these two are opposite methods you can just remove this presence of all elements located by when you're working with multiple web elements it will be
58:37
Speaker A
useful presence of element located text to be present in the element text to be present in the element located so these are all different methods so titles title contains visibility of visibility of all elements so when you put dot here expected conditions dot you will able to see all the
58:54
Speaker A
methods and you can choose which ever method is relevant to that particular scenario most of the times you can use visibility of element located because as soon as element is visible you can perform the action right so that is suitable for all kinds of elements you can try to use it and
59:11
Speaker A
if you want to use specific action like if it is a button and not only visibility you should able to click on that you can use element to be clickable suppose if you have some alert then you should
59:25
Speaker A
able to close that alert is alert present so that is a condition right so different conditions we can try to use the different scenarios okay so now we'll see what is an advantage and disadvantage of this explicit weight so I will put some points here related to this explicit weight
59:48
Speaker A
uh so the points the first point it is conditional based okay so implicit weight and thread do sleep purely based on the totally based on the time we specified but in explicit weight we are specifying the condition using
60:12
Speaker A
until method so it will work more effectively than implicit weight and thread dot sleep second Point finding element is inclusive okay so we don't need to write a separate driver. find element method so finding element is inclusive but not for every conditional method there are certain
60:35
Speaker A
methods uh for them we have to again specify the element finding element is inclusive most of the times third point it will wait for condition to be true then if the condition is still not true then it will consider the time it will wait for the condition becomes true it is waiting basically it
60:59
Speaker A
is waiting for the element because the condition should be true that's our ultimate goal here so for that it needs some time so the cut off time we are specifying at the time of declaring the explicit weight fourth point we need to write multiple statements for multiple webs and this
61:18
Speaker A
is again we can say a disadvantage but most of the times we don't write multiple things because very rarely we will get snation problem just one or two places and you can just take care of with explicit weight you can just apply the explicit weight for those two or three elements
61:37
Speaker A
that is enough okay these are the points we need to remember in case of explicit weight and even in implicit weight also there is a chance of getting an exception even explicit weight also there is a chance of getting an exception so only thing is we need to handle through track catch block
61:56
Speaker A
if still element is not present within 10 seconds you can safe side you can put track catch block the entire code you can put in the track catch blocks because almost in every uh weight statement is having the same problem if the time is exceeded the element is taking more than 10 seconds or more
62:16
Speaker A
than 5 Seconds still you have a chance chance of getting an exception okay so this is all about explicit weight so implicit weight and explicit weight now there is another flavor of explicit weight called fluent weight and this is more complex than explicit weight I think you seem it
62:41
Speaker A
seems even explicit weight itself is more complex than implicit weight right so fluent weight is a little more complex than explicit weight but these weights will works more effectively but if still not familiar with this you can still use implicit weight nothing wrong with this okay so let me show
63:02
Speaker A
you quickly how to use fluent weight it that is also part of explicit weight but the syntax we will change and we will add some more options in fluent weight okay now let me take another example 28 demo okay I'm just trying to remove this implicit okay so how to even in the fluent weight also we
63:44
Speaker A
have to first declare it then we have to use it two things so to declare the fluent weight again after driver creation here we have to create so how to create this fluent weight declaration so to declare the fluent weight we have to use uh something
64:08
Speaker A
called weight web driver and for this we need to create an object called my weight equal to new fluent weight actually you can also write fluent weight my weight equal to new fluent weight okay we need to type cash this is a syntax they have provided and you can just
64:34
Speaker A
remember this and we have to pass the driver here this driver we have to pass and uh after that we need to pass some more options here so this is the Declaration we have to import this weight from org open. selum support. UI and even flu we also we need to import and actually this is
64:58
Speaker A
completed Flint we declaration but we it is also provided some more additional options so we will continue that you can say enter you can say dot with the time with timeout here we pass duration dot of seconds let's say 10 seconds or can say 30 seconds and one more part is polling every
65:27
Speaker A
this is the additional option provided influent weight this option is not there in explicit weight you can say duration dot of seconds let's say five and uh last option ignoring ignoring and uh exception type you can specify I can say no such exception no such element exception
66:03
Speaker A
no such element exception and which is basically class so we need to specify that then close so this is the Declaration of fluent weight so ignoring no such element exception and this no such element exception should be part of org open G or selenium so this
66:32
Speaker A
is called declaration part PL weight this is we will get it from their own documentation so this is a fixed syntax we have to follow so we will try to understand these three options okay this is called declaration part and how to use this fluent weight for the element so for that
66:56
Speaker A
uh they have created one simple syntax let me see in their documentation and in the Google itself you can search for this google.com and you can search for fluent weight in selenium so you can just check their official website how they have created this so this is
67:23
Speaker A
the Declaration part and this is the usage how to use the fluent weight so they have given sample usage so let me put this point here this a syntax as it is we are using in our automation desps wait
67:45
Speaker A
okay so this is the Declaration and this is the usage and here actually the time we specify and here also the time we specify using duration dot of seconds so this is a declaration and this is a usage for the element so we need to slightly modify this actually so how to modify this we
68:07
Speaker A
will capture this first and this we need to write for whichever element it is taking uh whichever element is taking snation problem so we need to apply this okay so this is a declaration now I want to apply X fluent weight for this particular element okay so how to apply let
68:27
Speaker A
me comment this so this is the syntax they have given so we need to modify this actually this F is what web element I say txt username and web element we have to import and this weight is what is my weight object so that we need to pass okay until New function so these classes
68:56
Speaker A
we have to import so you can see com. google. common. base and web driver and web element these two we have to pass web driver and web element and this is basically called Arrow function okay in Java which is called Arrow function so in this public web element here apply web driver driver
69:20
Speaker A
and here driver. find element here whichever element you are looking for you need to write that so this is the element we are looking for this is the locator of this so we need to capture this by. ID or by. X paath this is the element we are looking for that you need to specify here here
69:41
Speaker A
we use find element okay so this is the full feder syntax so now you no need to write this statement so this is how we can use fluent weight for this particular element for one element so my weight is what the object of weight fluent weight because this is actual class which is
70:04
Speaker A
implemented the weight interface here weight is an interface so my weight do until this is actually the arrow function which is representing a condition and uh in this this method will find that element and return it okay so the major thing is these three x we need to understand how exactly
70:28
Speaker A
it will work so this is a normal time maximum time out normally we put 10 seconds right so here we put 30 seconds and what is the polling time polling every 5 seconds so this is uh a difference
70:44
Speaker A
between explicit weight and implicit weight so in explicit if you remove this option both Works similar way explicit and FL weight so this is the only option which will differentiate explicit and fluent weight so what is this polling every let us say there are two times we have specified 30
71:05
Speaker A
and five what is this 30 what is this five we need to understand okay let us say I have one element on the web page this is my element okay so our fluent weight will wait for this element and how
71:25
Speaker A
much maximum time 30 seconds maximum is 30 seconds and every 5 Seconds it will go and hit that element for example in the 30 seconds total 30 seconds how many FES are there in 30 seconds six right so first five seconds it will go and check the element is available or not if element
71:50
Speaker A
is available within 5 Seconds returns true and after 5 seconds again one more time it will hit that element if element is available it returns to or else it will wait for another 5 seconds and after 5 seconds again it will hit after 5 seconds again it will hit after 5 Seconds it will again
72:10
Speaker A
hit so for every 5 Seconds interval it will go and check the element visibility so how many times like this it will do till it reaches 30 seconds so here first 5 Seconds next 5 Seconds next five next
72:25
Speaker A
five next so totally 30 seconds maximum time it will wait but in between let's say suppose element is available within 5 Seconds it will return the element and then we can get this element in a variable and we can perform the additional action you can say txt username dot send keys off it
72:44
Speaker A
can directly pass the data here once we get this element suppose if within 5 seconds if it is not getting then another 5 Seconds it will wait then another 5 Seconds it will wait so this is called polling time polling every 5 seconds so this is not fixed value we can put whatever value
73:03
Speaker A
you want suppose if you want to pull in every 3 seconds you can change it as a three so then 10 times in 10 intervals it will wait okay that the difference between 30 seconds and third option is ignoring no such element exception okay suppose if uh in every 5 seconds if the
73:24
Speaker A
element is not not visible it will throw no such element exception right so this itself will handle that exception so ignore it will ignore no such element exception in every interval so first five seconds it is hitting the element not found actually it will show it will throw
73:45
Speaker A
no such element exception but it will not throw then it will go to another 5 seconds again hit the element no element found so it will not throw any exception so again it will go in every cycle or in every interval there is a chance of getting no such element exception so that we will ignore
74:04
Speaker A
by passing this parameter but after 30 seconds still this element is not visible still there is a chance of getting an exception that's the final exception that fluent weight also cannot handle only within the intervals if there is an exception comes it will able to ignore it
74:25
Speaker A
okay so these are the three options we specify in explicit sorry fluent weight and this is called declaration and this is what uses now once we get an element here that you can use TT username dot send the keys of pass ad like this and find element is Again part of this fluent
74:56
Speaker A
weight okay so sometimes it may work sometimes it may not work but don't worry let me just run it yeah so now we can see the values got entered in the username box so this is how we can simply
75:28
Speaker A
use fluent weight it is more complex okay so when you compare with explicit weight what are the difference is it will have these two options so it will work more effective than explicit weight and here also there is a chance of getting no such element except exception if this time is
75:51
Speaker A
exceeded okay but now we need to think about something here in every weight statement if the time is got exceeded still there is a chance of getting an exception right that is not solved in any type of weight it is not solved so what is the standard time is maximum 10 seconds even here
76:14
Speaker A
also you can put maximum 10 seconds and in every 2 seconds or 3 seconds you can pull for the element when I said two five times it will pull for the element okay so this is how we can simply uh do
76:31
Speaker A
it so maximum cut of time is 10 seconds if still you're getting issues right if the element or page is taking more time than 10 seconds you can put your code in TR catch blocks and then handle no
76:50
Speaker A
such element found and also you need to report this issue to the developers because that is a severe issue if you're not getting elements within 10 seconds that is a poor very very poor performance of your application so you have to intimate to the developers and try to fix it
77:07
Speaker A
and then you can come back and execute your code but temporary if you have chances of getting the exception you can still Handle by putting them in the TR catch block okay so this is how we can simply use weight state so whichever is which which statement we have to use very frequently so
77:32
Speaker A
all implicit weight explicit weight and fluent weights so when you compare these three again fluent weight will work more effectively than explicit weight and explicit weight will work more effectively than implicit weight but when you compare uh that is the way of working but uh
77:55
Speaker A
the usage wise very simplest one is implicit weight because we can just put only one single statement no specific classes no objects nothing one single statement you can put this and that is applicable for all kinds of statements so anyway you will put all statements in the
78:13
Speaker A
tri catch blocks by default in your automation test script so if there is an exception comes obviously that will handle it so when you compare with implicit weight explicit weight fluent weight so most of the times we can still manage with the implicit weight okay if you're having very
78:33
Speaker A
complex project and if you are familiar with the explicit and fluent weight you can still use them nothing wrong okay but start using implicit weight most of the times even I also prefer to use implicit weight because of Simplicity and uh exception is common right in every uh
78:52
Speaker A
weight statement there is a chance of getting an exception so that we cannot avoid only through TR catch block we can handle whichever weight you you are using in all kinds of weight TR catch block is mandatory required so if you look at in that particular aspect implicit weight is
79:08
Speaker A
more preferable at the beginning level but once you make advanced level once you go to advanced level and if you're working complex project then uh you can work with fluent weight or explicit weight okay so there is no specific default time like this default time is zero only for all kinds
79:28
Speaker A
of Weights default time is zero only but we need to put maximum 10 seconds don't exceed more than 10 seconds but if elements are even though it is loading within 15 seconds or 20 seconds it is taking still that is a very poor performance we should not accept it okay so we should fix those
79:50
Speaker A
issues and then again uh exit your automation code immediately you have to report them to the developer because they will take necessary actions and they can make website very fast so there is no limit for maximum timeout okay you can put whatever time out you want
80:08
Speaker A
but that is not relevant okay you can put 30 seconds but the element is loaded within 20 or 30 seconds your script will go fine but that is not acceptable 20 30 seconds is not acceptable it's very very poor performance 10 seconds itself is very poor performance
80:29
Speaker A
you should not accept even though it is loaded within 10 seconds no see if you're working on any web page if you're browsing any web page if it is taking too much of time as a user how you will fill will start frustrating with that right so according to the standards web
80:46
Speaker A
standards the elements or pages should be loaded within 3 seconds that is actual standard but in automation we will try to be up to 13 seconds maximum not more than that but still if you if your element is taking more than 5 Seconds six or 10 7 seconds in you can proceed with your
81:07
Speaker A
automation by putting 10 seconds Maxum time out but you have to intimate to the developers also whatever you noticed because they will work on performance Improvement and accordingly okay all right so just try to do this one round of practice is enough and uh most of
81:29
Speaker A
the times we try to use implicit weights to solve snation problems okay so I will stop here for today's session and tomorrow we will continue that just do one round of practice and even anyway in the coming sessions uh many places we will use this
81:48
Speaker A
weight statements because most of the times we will get synchr problems so whenever you get a synchr problems we will apply implicit weight instead of thread door sleep and then we will proceed further okay so that's all for today's session stop here we'll continue to
Topics:Selenium WebDriverJavawait methodssynchronization problemimplicit waitexplicit waitfluent waitThread.sleepautomation testingSDET QA

Frequently Asked Questions

What is a synchronization problem in Selenium automation testing?

A synchronization problem occurs when the automation script executes faster than the application can respond, causing elements to be unavailable and exceptions like NoSuchElementException.

What are the main types of waits provided by Selenium WebDriver?

Selenium WebDriver provides two main types of waits: implicit wait, which applies a default wait time for all elements, and explicit wait, which waits for specific conditions. Fluent wait is a variant of explicit wait with more options.

Why is Thread.sleep not recommended for handling waits in Selenium?

Thread.sleep pauses the script for a fixed time regardless of element availability, leading to inefficient test execution and longer wait times, whereas WebDriver waits are more dynamic and efficient.

Get More with the Söz AI App

Transcribe recordings, audio files, and YouTube videos — with AI summaries, speaker detection, and unlimited transcriptions.

Or transcribe another YouTube video here →