Welcome back.
Automation Masters.
Now, up until this point, we've ran this code quite a bit of times and you see that now.
I have a ton of Chrome browsers open.
That's not good.
How do we close these things?
Well, quite easily, actually.
All we have to do is say Chrome browser dot close.
Now this close method is going to close our browsers.
However, a lot of people sometimes have issues with this method because browsers are constantly being
updated and sometimes selenium has some bugs where it doesn't close this properly.
So this may work for you.
Now, in my case, if I run this.
All right.
Well, that actually worked.
But there are instances where this won't work, so you might have to actually call this.
Twice to make sure that it closes.
The instance now using close is going to close the current window that it's open, which is what we're
doing here with quit.
You actually get to close the entire chrome driver.
So let's do quit now and see if this works.
All right.
So that also quit the browser.
But if in your code for some reason you're opening up the browser twice, it's going to quit all sessions.
Unfortunately, because these swans are all past instances, it's not going to know how to quit them.
We should have, well, quit them from before.
So you're going to have to manually close these for now.
But at least now you know that you just add this at the end.
Sorry for showing you how to do that at the very end, but I had to keep it open so I can explain all
these things that are happening to you.
But ideally you quit the browser afterwards.
Now this quit and close actually causes a lot of headaches and sometimes it may not work on a browser.
This depends on the versions that you have installed.
There's a ton of forms online that you can look up and say, Hey, why isn't my browser quitting?
So it's a it's a heavily debated thing that you can find information online on.
If it doesn't work for you, you might have to call this twice or you might have to check that the version
you're using is working properly.
Now, some of you might be asking this gives you a lot of power, right?
Because I mean, I can start writing bots to go through websites.
Maybe I want to write a little bot that goes on every single Reddit post and upvotes it.
Or maybe I click like on a Facebook page over and over and over.
Maybe there's a voting contest going on and I can just write scripts to automate people signing in random,
people signing in and uploading, let's say, your submission.
So there's many good ways to use automation and many bad ways to use automation.
Maybe you want to send personal messages to your Facebook friends.
Well, you can automate it and message thousands of them all at the same time using something like selenium.
But you see websites are smarter than that because most websites will detect when it's a robot controlling
it versus when there is a human.
Because of how fast things are happening, no human is going to be able to send keys and click that
fast.
Right.
So selenium actually has thought of that.
If we actually go back here to the site that I originally showed you, which I'll link to if you scroll
all the way down to Waits, Waits allows us to actually wait and simulate actions at a bit of a delay.
So most people that write automation scripts on websites will use something like sleep or weight to
make sure that there's pauses in between actions so that, well, websites aren't going to say, Hey,
hey, this is this is definitely not a human.
I'm going to block their usage.
For example, here on the Udemy website, I tried to write a script that did things really, really
fast, and you'll see that Udemy actually blocks my activity and says, Hey, please verify that you're
a human, so that it says, Hey, I'm detecting something that makes me believe that this isn't a human.
I don't want our servers to get logged with all this activity because I mean, companies like Udemy
have to pay for, let's say, interactions on the website because they're talking to back end servers.
So you'll notice some of these things.
And you want to be careful with automation that you're usually testing on your own product or your company's
product, and that you're not abusing the other websites and trying to, let's say, game the system.
But using something like weight actually allows you to at least not do things as fast as possible so
you don't get detected as easily as possible.
With great power comes great responsibility.
And selenium is a great tool for testing.
A lot of companies hire testers and automation testers for this specific reason, and it's a great career
option for you.
However, you can also do bad things with this.
So be responsible.
Don't do anything that might get you in trouble.
Not advocating for anything of that, but I hope this gave you a little test into what automation testers
do.
And you can use selenium not just on browsers.
You can use them pretty much on any screen.
You can run them on Android devices, iOS devices, pretty much any screen.
I hope that was fine.
And I'll see you in another video.
Bye bye.