Hello, everybody, this will be the second part of lists topic now once we completed the basics part,
we will head over to the advance spot regarding lists.
And before we begin, I just want to give you a motivation why actually, we need to be masters and
less in this topic.
And we have a really simple reason for that, guys.
Sometimes further on, once we try once we start practicing selenium and start building our automation
end to end solution project, we will encounter elements that have elements meaning items in a website.
All right.
So sometimes we encounter some elements on a website which the identifiers, the ides of several elements
are the same.
And we would like to insert, for example, the text there containing in a list.
So first we will identify them and then we will insert all of the values at once into a list.
So we need to know how to manipulate a list.
I'll give you a quick example.
For example, you see here I have a table, all right?
I have a table.
I'm not going to go to specifics.
I tell you in advance, because we have a lot of hours discussing how to identify elements further on.
But just want to show you that I identified all the items inside this table right here.
And for example, in future lectures, I would like to extract the text all of these cells into a list,
into separate cells.
So starting you see, it's it's marked here.
So starting the first item, then the second and the third and so on.
So for this, I will definitely know.
I definitely need to know how to master list topic to use it.
So this was the motivation part of why do we need lists at all.
So we will use it a lot, believe me.
All right.
So let's begin.
First of all, we declared a list that we will use in this theory, part of advanced list topic.
All right.
So this is this will be our list and let's begin.
So, first of all, I would like to know the length of the list, the number of existing cells.
The countdown starts here from one.
OK, so we have like two topics, so you won't be mixed out with them.
We have the length.
All right.
Count.
Starts from one and we have the index indexes count.
Start from zero.
And what do I mean?
All right, so we want to know the length of the list.
So we just put the key word length, then brackets and put the name of the list inside.
And then once we try to print it, we will get the number four.
And why?
Because once we try to count the number of the cells, you're right.
This is the lank.
All right.
So the count starts from one.
So this will be one.
This will be two.
This will be three.
And this will be four.
So once we try to print it, we'll get the number four.
All right.
And in a difference from the lank, when we want to access the cells, the count starts from zero.
All right.
You you you I'm sure you remember from previous lecture, from previous practice lecture.
Once we want to access this cell, for example, it doesn't start from one star from zero.
So these cells index is zero.
So these two are not connected when counting the length of the of the list will start the count from
one.
But once we want to to address the index is once we want to go into the cells and extract the items,
we will start the count from zero.
All right, so let's go further to the next item.
All right, if you want to change the value of a specific cell inside the list, so let's say we want
to change the value in the cell in cell number one.
All right.
So cell number one is this one.
And all right, it's right here.
So and we want to set the value 10 inside of the cell that currently contains the one hundred and eleven
point nine.
We will just use the following action.
We will state the name of the list.
Then we have square brackets with the number of the cell inside.
OK, and then we have equals and the new value that we want to put there.
So this will replace this value with the value ten.
Pretty easy, right?
All right, so let's go over to the next one once we want to add an item.
To the end of an existing list, so if you recall in the last practice lecture, I gave you a bonus
assignment, which was assignment number eight search in Google, and I promise you that this topic
will be studied in the next video.
So here it is.
And what we want to do here, as is just to add an additional value to the end of the list.
And we saw in the previous practice video that we can use we can achieve it by the apparent action and
we do it in the following way.
We just state we just mentioned the name of the list and then we add that and add the append key action
action word.
And inside the brackets, we're adding the new value that we want to add.
So once we apply this action.
And what what will happen is just we would add a 15 value, a value 15 to the last sell, like an additional
sale will be added and it will contain the value of 15.
All right.
Done.
OK, so next in line is what happens if we want to add an item to a specific cell in the list.
All right.
So we want to add an item to an existing cell.
We just want to add an item to that cell.
So let's say we want to add the number one thousand and five to cell number two.
So we would have to use this action.
Just declaring the list, then using that, then using the keyword insert, then inside the brackets
will put the value that we want to add and then a comma and then then the number of the cell we would
like to add the value to this will cause the existing item of the cell to move forward to the next cell.
So what will happen is the following.
So we were having this list.
And we want to add the number one thousand and five to cell number two, so this is zero, index one
and two.
So what will happen is the following will be added to here.
And the item that was in cell number two would move over to the next cell like this.
So this will be, uh, what will we get after adding to the value one thousand five.
All right.
Breathe easy with the easy guys.
It's not very hard, just some key actions to manipulate.
All right.
So next one is how to remove an item by mentioning the value of it.
All right.
We want to remove a certain value out of the list.
So we just use the remove action key again.
First of all, just by mentioning the name of the list and then DOT and then the keywords remove and
then we state, then the the value that we would like to remove once we apply the S..
The value 1005 would be removed from the list here before moving to the next one.
Just want to mention that here we stated the value that we would like to remove.
And in the next next item here, we would like to remove an item by mentioning the sale index.
All right.
Here was the value and he would like to use the Salleh index.
So to remove an item by mentioning the sale index, we would like to use the pop action key.
All right.
And we can use the pop by two ways.
First one is mentioning the name of the list, then that and then pop and brackets.
This one would remove the last item.
All right.
This would remove the last item of the list.
This is the opposite of a band, right?
It's its sibling.
Because band will add a value to the end of the list.
It will create a new cell and add a value to it.
But on the other hand, if you use pop, it will remove the last item of the list.
All right.
So this is one way to use it.
And also we have another way to use it.
Also, name of the list that Bob.
All right, and inside the brackets, we can mention the cell that we would like to remove show here,
for example, I would like to remove cell index zero, meaning going up to the list.
I would like to remove the cell completely.
So once remove it, these are the cells that will be remaining at the list.
All right.
So pretty easy.
And this completes the theory part advanced.
Part of this is not very hard.
It's just using some action keys upon a list.
And we will see much examples in the following lectures.
I will show you coding examples of list manipulation.
And afterwards we will head over to the practice part, which you can practice the list at that spot
as well.
And that's about it, guys.
So see you in the next video.