Will be doing is that we'll be using this practice test automation.
Comm slash practice test login.
So this URL what it does is basically, as I told you in the last episode, also it helps you.
This is just to test now that a login system.
So it has a username and password, you can log in into this and it automatically creates a session
for you.
And if you have this session then it will say logged in successfully.
If you don't have this session then it will say so for example.
Then it will say that we are not logged in.
So you can log out and if the username is not correct, password is not correct, it will not log in.
Right.
So that's what it means.
So let's try to uh what we will do is we'll try our uh site.
Our bot will just go into this site, pass in the username password, click on submit.
Once it's logged in it'll save it as a cookies.
And once it's saved, the next time it runs, it'll run automatically with that cookies.
Because if they have the cookies, then the cookies have the sessions and that session is preloaded
with it.
That's how the system of Remember Me works.
Also, they save it as a cookies if you click on Remember Me in some sites.
All right.
So for this we have to remove everything.
Um till here.
So what we'll do is we'll just get that ID that URL.
So this is going to be here right.
Like that time dot sleep maybe at the end uh just for 100 seconds and driver dot close at the end.
All right.
So we have our, uh, you know, thing.
Now, what we'll do is we'll try to inspect this and see what the name is.
So we have a username or name.
So let's try to get it with the name.
So name is username.
So I can say driver dot find element element by dot name.
Name should be caps.
All caps.
And the name is username.
All right.
That is our username field equals this.
Let's try to get the password field also.
So password field equals driver dot find element.
Let's see what that is.
And we can get the thing inspect it is it also has name.
So let's just use ID in this case just to have differences.
So ID password.
Password is the ID.
So now that we have it, let's also have the submit button which is driver dot find element.
And let's see what it has.
It has ID so submit id so by.id submit.
All right.
So once we have all of these uh you know values saved, what we'll do is we'll send keys into the username.
Student is the key uh username and password also will send.
So send keys.
So the password is password 123.
And once we have that we will click the submit button.
So dot click.
So let's try this out.
Test this out.
Let's see if this works.
So it goes into this sends the thing.
Now it just logged in successfully.
That's awesome.
So we are logged in.
Now if I want to let's say I want to save this thing into a cookies.
How can I do this.
So I can do this by using a another module called pickle.
So pickle is the module which we can use in order to write into a cookie right into cookie.
So I can say.
So at the end we have to save uh, sleep for five seconds so that everything is loaded and we are good
to go with cookies.
So we are now loading, uh, dumping the cookies.
So we are saving it.
In other words, right in the word of programming, they call it dumping.
So for that we have to install import pickle.
If you don't have pickle you can also do pip3 install pickle.
And what we will do is basically we will say pickle dot dump.
So pickle dot dump.
What we will dump is driver dot get cookies.
So cookies.
So it will get the cookies and you know dump it.
But where will it dump it.
So we'll open cookies.
Dot Pql Pql is the, uh, you know, uh, extension for pickle.
So WB is write binary.
So we'll be writing into binary right into this cookies.
So everything will be written in the binaries.
So once that is done then we can just we are good to go.
So now what I will do is I will open up our file system file.
So.
Let's just run this.
So I have got this here and the the file system is this.
So let's see if it creates our cookies or not.
So it slips for five seconds and the cookies is ready.
So the cookies is created, which means our login system was also created.
So what we will do is the next time it loads, it will have to go into this cookies and read all the,
you know, files of these cookies, all the data of these cookies, and feed into this website.
So that's what we'll be doing.
So what we will do is we will say only do this only use username and password.
If the cookies file does not exist.
For this we'll need another library called OS which will say OS dot path dot exists.
So if that exists means cookies dot SQL exists then do.
Then we will do something.
So this is if that exists then we have to um, you know uh open the cookies file and load it.
Right.
So this would happen only else.
So only if that thing does not work.
If the cookies does not exist only then.
So let's try this thing.
So cookies exists.
So let's say this now.
If I run this, nothing will happen for now because we didn't load the cookies.
But it will say cookies exists.
You can see cookies exists.
Now we can say load into this thing so we can load our cookies to load into the cookies.
We can say, uh, what we can say is we can say cookies equals.
So we can say pickle dot load.
So we can load the pickle file.
So previously we used dump.
Now we will use load.
So we will load open.
We'll open that file cookies dot pkl with the read binary.
Uh read binary.
So previously we used w binary which is write binary.
Now we'll use read binary.
And we will basically say for cookie.
So there are lots of cookies into one cookie file.
So we will say for each cookie inside the cookies.
So for one cookie second cookie.
So for each cookies right.
So for each one of them we will add every one of that cookie into our driver dot cookie.
So if that works and we will let's say time dot sleep for some time let's say five seconds.
That should pretty much do our thing.
Let's try this out once.
So it should open it.
And it should say that cookies exist.
So cookies file does exist.
And if it does then it has to pass in that cookies.
But it seems it didn't pass.
So it seems that uh, that particular, you know, website does not accept cookies.
If it did, if it did, uh, us accept cookies, then this would work.
So the cookies was added.
So this we can check out when we say, let's say let's sleep for some seconds, let's say 100 seconds.
And we just go into this and we can see into the stories if that cookies were saved or not.
So let's open our cookies file.
Let's wait for some time and let's see our, uh, inspect the settings.
So we see our, uh, stories and everything.
So inside here we can see all the things.
So let's say memory.
Um, uh, or let's see network sources.
Console.
Yeah.
Here.
Cookies.
So, okay, this seems to be, uh, a web WordPress thing.
So it does not hold the cookies, but, uh, I'm just trying to show you how we can use this into other
things.
We can actually try to find a proper, you know, working thing.
So cookie test login system to just test it out since we are just doing it.
Um, let's say anything using cookies.
Test login system.
So.
Ideas for testing test cases.
Okay.
Anyways, I think, uh, it will be hard, but, uh, what you can do is you can try this with, um,
actual login platforms.
Just make sure that you hold the rights.
So if you have created a certain systems, uh, that needs, uh, a particular login system, then you
can use this.
So the main thing is we want to dump into this and otherwise we want to, uh, load from it.
So that's how we do it.
All right.
Uh, even though we could not see it in action, uh, this is how we do it.
And we saw the cookies being dumped.
By the way, if we open that cookies file, then it would be hard for us to understand because it's
in the right binary.
Right.
So, yeah.
All right, then the next chapter in the next session will be learning how to we can execute JavaScript
snippets, uh, into our, you know, um, selenium uh, web browser.
So that's what our next thing would be.
And after that we'll be looking into other things.
So I'll see you in the next one.