Master Selenium WebDriver Commands: Application, Conditional, Browser, Navigation, and Text Handling
Introduction to Selenium WebDriver Commands
This session covers various Selenium WebDriver command categories to interact with web elements and control browser behavior.
Categories of Commands
- Application Commands: Get page information such as title, URL, and source.
- Conditional Commands: Validate element properties like visibility, enablement, and selection.
- Browser Commands: Manage browser lifecycle with
closeandquitmethods. - Navigational Commands: Control browser navigation with
back,forward, andrefresh. - Wait Commands: (To be covered in subsequent sessions.)
Application Commands
- driver.get(URL): Opens the specified URL in the browser.
- driver.title: Retrieves the current page title.
- driver.current_url: Fetches the URL of the current page.
- driver.page_source: Returns the full HTML source of the current page.
Usage Example
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service('path_to_chromedriver')
driver = webdriver.Chrome(service=service)
driver.get('https://example.com')
print('Title:', driver.title)
print('URL:', driver.current_url)
print('Page source length:', len(driver.page_source))
driver.quit()
For a deeper dive into Selenium automation basics and initial setup, consider the Comprehensive Selenium WebDriver Tutorial: Setup and Basic Automation.
Conditional Commands
Used to verify element states; all accessed via WebElement objects:
- is_displayed(): Returns
Trueif the element is visible on the page. - is_enabled(): Returns
Trueif the element is interactable. - is_selected(): Returns
Trueif a checkbox or radio button is selected.
Practical Application
Check visibility and enabled state of an input box, or selection status of radio buttons and checkboxes before performing actions to ensure robust script behavior.
Browser Commands
Manage the browser instance with two primary methods:
- close(): Closes the focused browser window but leaves the WebDriver session running.
- quit(): Terminates the entire WebDriver session and closes all associated browser windows.
Key Differences
| Feature | close() | quit() | |--------------------|--------------------------|---------------------------------| | Number of windows | Closes only current window| Closes all windows | | Driver process | Process remains running | Process is terminated |
Navigational Commands
Simulate browser navigation:
- back(): Goes back to the previous page in browser history.
- forward(): Moves forward in browser history.
- refresh(): Reloads the current page.
These are accessed via the driver instance and allow efficient navigation control during automation.
Finding Elements: find_element vs find_elements
| Aspect | find_element | find_elements | |----------------------|----------------------------------------|------------------------------------| | Returns | Single WebElement | List of WebElements (can be empty) | | If multiple matches | Returns the first matched element | Returns all matched elements | | If no element found | Throws NoSuchElementException | Returns an empty list (no exception)|
Practical Tips
- Use
find_elementwhen expecting a single unique element. - Use
find_elementsto retrieve multiple elements, iterate over the list for bulk operations.
Example of iterating multiple footer links:
links = driver.find_elements(By.XPATH, '//div[@class="footer"]//a')
for link in links:
print(link.text)
Extracting Text from Elements: .text vs .get_attribute('value')
.text: Retrieves the visible inner text (text content between the opening and closing tags). Useful for links, buttons, labels..get_attribute('value'): Retrieves the value of an attribute, commonly used for input fields to get their current value.
Important Distinctions
- For elements like input boxes,
.textreturns empty because they have no inner text; use.get_attribute('value')instead. - For elements like buttons or links,
.textreturns the clickable label.
Example
input_box = driver.find_element(By.ID, 'email')
print(input_box.text) # Usually empty
print(input_box.get_attribute('value')) # Returns input content
button = driver.find_element(By.ID, 'submit')
print(button.text) # Returns button label
print(button.get_attribute('value')) # May be empty if no value attribute
Summary
- Selenium WebDriver provides categorized commands for page info retrieval, element condition checking, browser and navigation control.
- Conditional commands ensure element readiness before interaction.
- Use
close()andquit()judiciously depending on the need to close single or all browser windows. - Understand differences between
find_elementandfind_elementsto avoid exceptions and correctly handle multiple elements. - Extract text or attribute values smartly using
.textor.get_attribute()depending on element type.
Practicing these commands greatly improves your automation scripts' reliability and efficiency.
For broader context on web automation and related tools, you might find Exploring Puppeteer and Headless Browsers: A Comprehensive Guide insightful. Additionally, strengthening your understanding of HTML and CSS can be beneficial; refer to Comprehensive Guide to HTML and CSS: From Basics to Advanced Techniques for a detailed exploration.
okay so from today's session onwards we are going to see how we can work with the different type of web driver commands because so far we have seen like how we can identify the elements on the web applications so once we identify the web elements so the next
thing is we need to perform the actions so the different elements are having different type of actions so to perform the actions web driver is provided different type of functions or methods by which we can perform the operations okay so let's see what are those commands are available
so mainly we have get commands so we categorize into multiple types we can call them as get commands we can also call them as a methods okay methods or functions whatever is get commands and then second category is conditional commands [Music]
conditional commands and the third category is browser commands and then navigational commands and finally we have a weight commands so these are the five categories of commands which are provided by selenium webdriver and each category there are multiple commands are available so i'll
show you how to use those commands practically and where to use them and apart from that apart from discussing these commands i will also show you how to interact with the different type of elements like how to interact with the input box or text box and what are all validations we can do on that
and then how we can interact with the radio button check boxes drop down buttons or links images there are different type of elements we can see on the web page so how we can interact with those elements like how we can perform the different actions on those elements i will also
discuss them parallelly along with these commands okay so first let us start with the get command so what are the different commands are available under get because these commands will basically uh called as a getting the information like getting the title of the page or getting the
url of the page or getting the html of the page so for that we use this command so we can simply say uh get commands okay so what are the commands are available so we instead of calling get commands we can simply call them as browsers uh browser-specific commands
okay i can say application specific commands like application title application url application based override we can call them as a application related commands because in celine with the java we can call them as a get command because all the commands will start with the get keyword but here
we don't have such keyword so we can directly say title current url pay source like that so we can call it as application commands so application commands conditional commands browser commands navigational commands and weight commands so these are the totally five types of commands we have now
we'll see what is application specific commands the first type is application specific commands what are they the first one is a title and all these commands we can directly access through driver instance or driver object so title and the second one is current underscore url
the third command is page underscore source but uh when you learn selenium java so where we have a different method like get title get current url get paid source the same thing here we have only title current url peso this here these are not methods actually and they are the keywords or
which are actually variables built in variable which are already available in driver instance so we can dynamically get the title of the page url the page and source content of the page so i'll show you how to use them practically so let's go to pie chart and see how we can work with
this application specific commands go to pie chart and let's create new directory today i say day 15 so inside this i'm just creating a new class new python file i'll name it as [Music] app commands application commands it says app commands so this is a python file which is created so as
usual first we need to import the web driver module and then we have to import the service so these two uh packages which we have to specify and now we need to create a service object and driver instance so in the service object we have to specify the location of the driver and this is
our service object and after that what is the next step is we need to create the driver object so how to create driver equal to webdriver webdriver dot currently i'm taking chrome browser so here don't forget to pass this service object because this needs a driver location so this is a setup part
and once this statement is launched our browser then we need to open the application urls how to open the application url so we have a method called driver.get so this is actual method get is a method so here we can pass the application url so whichever application you want to open
you can just pass the application url inside this get method and this will basically open this application on the browser and we can say this is also comes under this application but this is actual method not a commander suppose as soon as you launch your this application i want
to find the title of the web page so i want to get the title of the webpage so for example so let me open this application i want to verify the title of the page is correct or not so how we can verify that first of all we need to capture the actual title of the page and then i can compare the same
title with my expected title but where we can see that actual title on this page if i just right click on the page and inspect this page and here in the header tag you can see the title tag in the header you can see the title tag so this title will be the different from one page to another
page so each page is having a unique title so this is actual title of the page so i want to capture this title of this particular page so for that we use one more command called driver dot title so driver dot title so this will give you the current title of the page or title of the current web page
so how we can print it we can just simply print or we can store the title in a string variable later we can compare it so this will return the title of the current web page and suppose i want to verify this applications url is correctly open or not so as soon as you specify this url the
same url should be open on the application so i just want to verify this url is correct or not so randomly or dynamically the runtime i want to capture this url so we will give this url there is one more command called current url simply say driver dot current
underscore url so this will give you the current url of the application so that you can print it so later on i'll show you how to use all these things uh to perform certain number of validations on the web page so first we'll see how to capture them so driver or title title is one command
and current underscore url is another command which will return the current url of the web page and these will these are actually variables which we can access through driver instance and first let us execute these commands and after that i just want to close my browser
for that i can say driver dot twitter or driver dot close you can use let us try to execute now yeah so it is giving some error now what is an error it is giving webdriver dot chrome service object and this statement is giving an error let's see is there any mistake here
service is equal and this is a actual path driver equal to web driver dot chrome service object so here we have to specify the variable right so i say service service equal to service object right so that's the syntax so we should not just pass only object
we have to specify the variable service equal to service underscore object now let us execute now it is launched my web browser and launch your application then as soon as you capture the data from the page it is automatically closed because we use quit command right it is automatically
closed now you can just look at here this is actual title of the page which is written by this particular statement and driver of current url this is a statement which is written the current application url or current app url
and similarly we also have one more command called driver dot page underscore source page underscore source basically this command will give you the source of the page what is the source of the page if you just right click on the page go to view page source here and
this will show you the source of the page and basically which is the source code contains a html css along with the javascript the whole code is there inside the source page actually this is a source code which is written by the web server and the same code is a presenting on the ui in
the user understandable format actually the server is written this one when you send this particular request okay and this is just a user understandable format in the ui format it is displayed so if you want to capture the source code of the webpage like this
then we can use this command so what is that command page underscore source but what is the use of this command if you want to do some validation on the source page or page source and what we will do is we will just capture the entire source of that particular page into some
variable and we can verify something is present on the pesos or not or something is not present or not we will verify that so in those cases we use this but very rarely we use this command because we don't need to do anything with the source code but still if you want to evaluate
something in the html basically source code is a html only right so if you want to do some validations on the html then we use this command or else not required so this is another variable which we have so which is return the source page content or the html of the particular page
so we can just execute inside the print command so these these variables just written the data okay or values we need to use additional print function to display the data let's execute one more time right open the browser launching the application url and is also closed now we can just look at
this this is all about html or the source code of the page which is completely captured here and displayed this is having huge code so it is completely captured fine so these are the few method or few commands which are available we can call them as a application related commands
web driver application related commands so what are those commands get is one method basically which is used for uh opening the application opening the application url and what is the use of this command to capture the title of the page you have to remember this okay to capture the
title of the webpage of the current web page and the third command current url so which is use refer to capture the current url of the web page and pay source which will to capture capture source code of the page so these are the four commands which are comes under application
related commands basically these commands will uh get some information from the application basically get will open the application title will return the title of the application or current url will return the url of the application similarly pay source command which written the
source code of the application so all these commands are basically working for the application so we can call them as a application related commands so apart from them so we also have a few more commands called conditional commands second category conditional commands so most
important commands listen carefully so what are the conditional commands which we have there are more number of conditional commands we have so let me just list out here then we will discuss one by one so the first conditional command is is underscore basically these are
all methods okay is underscore displayed this is one method is underscore displayed is underscore enabled this is one more conditional method is underscore selected is displayed is underscore enabled is underscore selected so these are the three conditional
commands which we have is displayed ease enable eselector and when we use this command especially for checking the status of the element for example i want to check the element is present on the page or not suppose i want to enter some text in the input box before entering the text i want to check
whether the input box is first of all available or not on the web page which is displayed or not for that i can use this method so what this method will do this particular method will check particular element is present on the webpage or not
and if it is available or if it is displayed then this method will return true that is a boolean value if that element is not available on the page then it returns false similarly the next method is e is enabled if the element is enabled then returns to if it is not enabled written false
so what is enabled and disable status means sometimes element will be there but you cannot perform any action on the element suppose you can see some input box but you cannot enter any value it is not allowed you to enter any value in the input box so that is basically called as
a disable mode so if it is enabled then we can do some action on the element if it is a disable we cannot do any action so this particular method is underscore enabled method will returns true if the element is enabled and this will return fast if the element is disable state and e is
a selected especially used for radio buttons and check boxes because in the radio buttons you can see multiple radio buttons as soon as you selected some radio button like before selecting the radio button if you use this method it will return false but after selecting the radio button if i use the
same method again on the same radio button it will return true basically this particular method will check that radio button is selected or not if it is already selected returns true if it is not selected written false similarly same thing for checkbox also we can have multiple check boxes
and uh if the checkbox is already selected returns to if checkbox is not selected written first so especially this particular command will use for radio buttons and check boxes but rest of the two commands we can use for any kind of element it can be redo button check box input box image
link whatever element you want to check whether it is displayed or not you can use the first method is underscore display or if you want to check the element is enabled or not then you can use ease underscore enabled and if the checkbox is already selected or not you can check or
if the radio button is selected or not you can verify by using ease underscore selected method so basically these three commands are returning a true or false because they are checking the condition whether they're displayed or not enabled or not selected or not the condition based methods
so we can call them as a conditional methods now we'll see practically how we can use this conditional methods along with them i will also show you how to interact with the check boxes and also input box and different type of elements so go back to the pie champ and
let's create one more python file and i'll name it as uh conditional commands okay so conditional commands so let me just copy this code from the previous example let me just launch my application i say driver.get so here i'm using one application called
newcomers.com registration page so in this page you can see different type of elements right so you can see two radio buttons you can see some input boxes and so on there is one check box so multiple elements you can see here so first of all let us start with
two methods is displayed and is enabled and then i will discuss about e selected okay so let's go back to the application copy this url and put in the double quotations so as soon as the url is open then i'll try to maximize the browser window how to maximize driver dot
maximize underscore window so this will maximize the page right so once you maximize the page now the first command is what is underscore displayed this is one method and the other one is is underscore enabled is underscore enabled now we'll see how to work with these commands
is underscore display is underscore enabled so in this particular page okay so in this particular page i have a small search box here and there is search button also there so basically or you can just you take any other element no problem so let me just take the search
store here so i want to check this particular element is displayed in this page or not i want to check this element is present here or not so how we can do that first of all we need to identify the element so first inspect this element and uh you can just use a crow path or
if you want to write any xpath locator you can write it so in this you can see selector have been suggesting all the different type of locators here because this option is recently again enabled so these options are all the locators are displayed here so you can just take one of the
path like this so let me use this x path and find that element driver dot find underscore element by dot x path in singular double quotation specify it because i put in the double quotation here right so by also we need to import from selenium webdriver commas by by so now this will able to
find that element right so we can just store that element in a variable i will name it as search box search box so now i capture that element inside this variable right now what this variable contain so this variable contains a web element whatever the web element
this statement is pointing and that web element will be captured into this variable right so now we need to check which is available or not so take this variable or web element dot now we can use we can access that method how to access is you can just
type is automatically conditional methods will be displayed is underscore now you can see is underscore selected is underscore enabled is underscore display three methods are displayed so is displayed i'm taking is underscore display so where these methods are available
so these three methods or belongs to web element okay and these commands we can access only through driver instance but these methods we can access through web element not from the driver we should not say driver dot is display driver dot enabled no these methods
we can access only through web element so this particular command is return the web element store in this variable then i am checking whether this displayed or not so what this method will return true or false so let's just print that value print search box dot is displayed
all right so it should display true or false i can just write some message also you can just in double quotation i say display status and similarly i want to verify the enable status okay it is displayed fine but whether it is enable
or not enable means what it should allow us to pass some value here like this then we can say this is a enable state so i want to verify this is enable state or not the same element so what i can do is you can just copy the same statement because it is the same
same element we can just copy the same element and instead of is displayed i can say is enabled is enabled this is a enable status this is enable status now we verified is displayed or not e is enabled order so both will returns either true or false depends upon the status of the element
okay now after that i'm just trying to close my browser or we can just quit from the browser it went very faster so let me just run one more time yeah now it is my browser launching your application so immediately it is capture
the status of the elements closed now the display status is true enable status is also true because by default they are displayed and also it is enable state sometimes in your application your element may not be displayed properly so then it returns false suppose even
the element is available sometimes it may not be enable state in that case you will say false so these commands are specially used for validation purpose at the element level okay so these are the two commands which we can use it for any kind
of elements you can use like is displayed or reason enabled or not now the third command is is selected is underscore selected and this is also conditional command especially we use it for radio buttons and check boxes whether they are selected or not we can check it
so only for radio buttons and check boxes we can use this command so for radio buttons and check boxes now we'll see how we can work with this command if i just look at this page okay so here i have few elements and here you can see gender
element male and female so these two are the radio buttons so by default when i launch my application none of them are selected so male and female none of them are selected right so what i will do is let us capture the status of these two elements
like whether selected or not i want to verify so for that what we will do is first we need to capture these two elements radio buttons we have to capture so how to capture these radio buttons again right click and inspect and you can see go to selector hub again so this is a xpath
which is generated for mail header button copy this xpath or you can write your own xpath here go back and try to get that element driver dot find element you can use any locator okay most of the times i use only x bar so find underscore element by dot x path
and this is my x-bar and this is a mail radio button so i can say rd radio button underscore mail so i capture one radio button and similarly let us try to capture the second one this is a female variable so to copy this you can just click on
the relative x path here automatically copied here go back and write one more statement driver dot driver dot find element again by dot x path with double quotations copy the x path so this is a
another element rd underscore i say female so now i capture the two elements two radio buttons but by default none of them are selected male and female okay no one is selected here so when i see the status take this first element dot is selected and just print the status let me say here print
okay so okay just print the default values okay so this will print one thing and then check the status of the second one also instead of rd underscore let's say rd underscore feedback so basically what i'm doing here i've just captured the two radio buttons
as an elements now i'm checking the status of the first element here e selected or not and also checking the status of the second radio button right let's execute and see now so the default by default they have not selected so what we are expecting
is both should return false okay now it is executed very fast let me run one more time yeah it is launching my browser application yeah closed now you can see both are returning false this is our expected because none of them are selected so this is false and this is also false
fine but now what i will do is i'll just go and select one of the radio button let's go and select the first one so let me just go and open the browser application right so now i want to just select the first radio button how to select the first aid button how to select it radio button
if you want to select what you can do is take this radio button element dot click just click ok so this will automatically select the radio button so here it will select mail radio button so after selection of radio button what i will do is i will again
capture the statuses of the both elements so here i will write something like after selecting mail radio button okay and here what we are expecting after selecting mail editor button so i'm printing the status here
we can say i'll write one more statement or else okay so let's print this one after selecting the radio button i'll write one pin statement print like this so after selecting the data here already selected after selecting the radio button mail radio button so again if i check the status
it should return true right they should return to because we already selected here but what about the female radio button so that should not selected because at the time you can select only one radio button if i select only mail header button still female is still false
now we'll check these two statuses correct or not so these two are before selecting and after selecting let me write one more statement also here so default statuses i said default radio buttons status
so default radio buttons status and after selecting the mail header button again we are checking here let's run one more time so now by default none of them are selected so fast and fast but after selecting the main
red button what happened the first radio button status should be becomes true and now second one is still false okay now let us select the second radio button now so here instead of first radio button i'm taking the second radio button and perform the click action now the results will be
reversed so now after selecting the female radio button what happens the first radio button status become again disable right it will not selected so here after selecting female leader button now this should become false and this should becomes true let's execute now again
all right so now we can just look at here the default status is both false and then after selecting the first mail you do button the first one becomes true second one is still false now after selecting the female leader button the first one become for second one becomes a true
so like this we can just verify the status like whether they are selected or not we can verify similarly we can also check whether they are displayed or not enabled or not so these commands work for all kinds of elements is this very easy number we can still use it
for radio button check boxes but ease selected is a method which mostly used for check boxes and radio buttons whether the select status is selected or not which is already selected or not okay so these three all comes under conditional commands or we can say conditional methods
in selenium webdriver okay so this is a one category so we have seen two types of commands so for application commands conditional commands the next category is browser commands only two commands are there so what are those browser commands close and quick
close and equate so both are not exactly the same there is a difference i'll tell you close quit so these two commands are called browser commands not application commands application is different a browser is different okay once you open the browser then we can open the application on the
browser so these commands works on the browser level but these commands works only if you open the application okay so remember the difference between this one and this one so now we'll see how to work with the browser commands close and quicker most important listen this carefully in
interview people will ask the question what is the difference between close and quit ok so for that i am just going to show you one simple example go back to the pycharm close this example let's create one more file i'll name it as browser commands
okay so here i'm just importing uh importing stuff from my previous example like just copying this okay now let's launch our application so before that let me show you that application go back to the browser
and this is the url of application so look at this carefully so in this application this is a current application which i have opened on my browser right so when you do click option in this link so when i do click action on this link you can see some bottom there is a link
called hrmink right so when you do click on this link it is opening another tab in the same browser so this is another page or another url you can simply say totally come to first one second one is having a different url so now how many applications are open there are two applications
are open on the browser so you can consider this is one browser this is another browser okay now let us see the difference between close and quit what close will do what quit will do because if you have only one single browser like this both works in the similar way what they will
work what they will do is basically close command or close method will close your browser similarly quit also do the same thing bit command will quit from the browser but internally there is a another difference is there the close command will simply close your browser but still the
browser specific process will keep on running in the bucket that process will not be killed but in every process in windows or unix or mac in any operating system if you start some application there will be some process will be created internally okay and when i use a close command you
can just close a browser but still that process keep on running that process will not be killed but it will close a single browser but when you use quit command which will also close your browser along with the process the process also automatically
so there's a one difference the second difference is a close command will close only one browser at a time but when i use quit command which will close all the browser if you have a 10 browsers are open all 10 browsers will be closed by quit command so
they are the differences between close and equate commands now let us see practically how they work so here first of all i am launching my application i say driver.get and go to the application let me copy this url
this is my application and as soon as i open the application i just want to maximize it how to maximize driver dot maximize underscore window and then i want to perform the click action on this link inspect this element
and in the selector hub you can see multiple locators here so let's go with the link text or partial link text whatever so i'm just taking the link text and here i say driver dot find l find underscore element by dot what is the locator we have to take
link text but it is not suggesting anything here why it is not suggesting because we haven't imported by class so we have to import that first let me import the buy also okay now you can just look at it by dot so link test i'm using so link underscore text comma in the
double quote or single quotations we have to specify the link text this is our linked text so this element we found and then perform the click action directly on the link so what this statement will will use what this statement will do this statement will perform the click action
on this link then automatically one more browser window is open so now currently how many browser windows we have the first one and the second one right now i'll use one command called driver dot close now see the difference i say diver dot close okay say only driver.close just observe this
and what i will do is as soon as i click on this link immediately the page will open and close so you cannot see the difference so after clicking on this link i just want to wait some time here i want to pass my script for some time and then i will do this action so if you want
to pass your script for some time you can use one command from python that is called time okay time is a module which is there in predefined in python so time dot you can use a sleep command here you can specify the time in seconds just i want to wait for five seconds you can say five seconds
so it is just additional command i'm giving you because it will go very fast as soon as you click this it will immediately close the browser so you cannot see whether it is opened or not so just i want to show you the pages are opened or not then which place is just closing that we want to show
you so that's the reason i'm just putting wait time here okay in java we have a thread dot sleep so it is also similar to that comma in python so let's execute now and uh observe carefully now we can just look at here it is launching my browser opening the application this is
the first application we opened immediately it is also opening the second browser and observe this carefully now the first one is automatically closed but second one is still open second one is still open the first one whichever the url we have opened this is got closed but after
clicking on this link what is a new application our new browser is open that is still available so that means what we need to understand here what we should understand here is which which page is closed we can just consider as this is a parent browser or after clicking on this
link whatever application or browser is open we can call it as a chill window for now i can call it as a parent browser window i can call it as a jail browser window so which one is closed it is closed parent browser window that means whatever applications at the beginning we have open that
is got closed but whatever application newly opened by this link which is not still closed what does it mean the close method is closed the application whichever we opened at the beginning that means our driver is basically focused on the previous browser or previous application
so even though this statement is open the another application or another browser still our driver focuses on the first application it's not directly shifted to the second application so our driver whichever browser application or whichever browser window our driver is focused
so that particular browser window will be closed so that's what we need to understand here the close command always close only one browser at a time so we have opened two browsers but it is not closed both it is just closed only one browser window that's the first thing second thing
is what which one it is closed the parent window so that means wherever or whichever browser window the driver is focused and that particular browser window only closed and other browser windows still open even if you have open 10 browser windows it cannot close all 10 and either at least one page
will be there one browser window will be there where your driver is focused so that browser window only will be closed so that's we need to understand by close command okay so what is the use of close method or close command close single browser window close single browser window
and again condition applied what is the condition the driver should focus whichever browser the driver is focused and that particular browser will be close up close single browser window where driver focused i you will understand uh in detail what is draw a driver focused and all these
things in the next examples okay don't worry so for now just understand in whichever application we are opening at the beginning still our driver is pointing to that application it cannot shift to the new application which is open by this link just understand only this much for now okay in
the coming sessions i will show you uh one more scenario what is browser window what is that and then you will understand clearly okay now this is a close command guys so this is one command close single browser window at a time where the driver is focused now what about the quit command
and instead of close i am trying to use a quit command driver dot twitter driver dot peter now observe this same thing instead of just close command i am using driver.kit execute see this currently the two pages are there first pages second page you can see the tabs also
now both are closed this time both are closed so that means what quit command will close close multiple multiple browser windows multiple browser windows but this is the actual difference we can see as a user at the front end but internally what exactly
happening is each browser window as soon as you initialize a process or as soon as you start some process there will be process id will be created or some process will be created by the operating system for example when you launch your browser like this there will be process created by the
operating system similarly when you open another tab also that is also one another process and when you open another tab this is also another process so fairly every action the windows will be created a process which will consider as a process now in the close command what happens it is simply
closing the browser so when i open this one i open application so it should close a browser but still the process internally runs which will not kill the process that's the reason is able to do only one single browser but in the quick command what exactly doing is whatever the driver
we initiated here chrome driver it is killing the process which is related to this driver so that means the entire browser operations works based on this driver only right so what fit is doing basically quit is not directly closing the browsers it is not directly closing the browser
it is internally killing the process of chrome browser basically killing the process of chrome driver that's automatically close all chrome driver processes whichever the chrome browsers launched through your automation script and those browsers automatically closed because it is
internally killing the driver process not directly on the application so that is a hidden difference actually which we cannot see physically but quit command will basically kill the driver process itself so that's the reason which is able to kill all which is able to close all the browsers
as a user we can see just it is closing my browsers but what exactly happening internally is it is basically killing the driver it is killing the driver okay so remember that most important so close command close single browser window at a time whereas quit command
close multiple browsers windows and in addition this will kill the this will kill the process okay so these are the differences between browser commands close and quit command and uh here everybody will know this so if anyone ask an interview
people will answer these two questions what is close what is bit what is the difference and close command will close single browser at a time fit command will close multiple browsers but there will be another scenario for example i have multiple browser windows
like this have 10 browser windows i want to close specific browser windows based upon our choice that's my requirement let us say i have 10 five different browser windows let's say i have one let's say two three four five browser windows i have open but i when i use a close command what
happens first time whenever whichever browser we open only that one will close or whichever browser window our driver is focused only that particular browser window will be closed only single browser will be closed but when i use a qit command what happens it will close all the browsers
which will close all the browser windows but my requirement is i want to close only specific browser windows i want to close on second and fourth i want to close only first and third i want to close only four and five how is this possible so this is also possible by using
another commands window handle commands are there so when i discussing about those commands then i will tell you how we can handle this scenario okay till then just remember this which is also most important in entry question okay because we have a separate uh session for this how to
work with the multiple browser windows so this concept is related to that so i'll explain it that time for now i'm just keeping this so understand what is the difference between close and quick okay now so so far how many commands we discussed how many categories we discussed three categories
right application commands conditional commands and browser commands and the next one is navigational commands navigational commands how to work with the navigational commands it is also very simple and very easy so normally uh when you open any application so
let me show you suppose here i open one application let us say i just want to open just notice uh observe how i'm doing snapdeal.com so this is the application i have opened here this is one browser window right so in the same browser window i'm just replacing this url with amazon.com
same browser window again now i want to see my previous application i want to see my previous application so do i want to i do i need to again type the url here not required right so i can just click on this arrow mark then it will go back to my previous application
how is how it is happened like this how it is happened like this because the first time when you open this url our browser is remembering this our browser is remember this and if after remembering again when i open second url again secondary url also it is remembered so
if i use this arrow keys like this go back you'll get the previous application if i just click on this forward arrow you will get the amazon dot in so first time when you open any two applications like this you can navigate between these two applications by just clicking on this arrow marks
and what is the users or what is the user for these two rm marks just for navigation purpose and this is another option which is reloading the page if you want to reload you just click on it the page will be reloaded or page will be refreshed the same operations we can do through automation
script by using navigational commands okay now i'll show you how to use navigational commands to perform these operations let's go back the next type of commands are navigational commands so what are the navigational commands or we can say navigational methods
are available and only three methods are there one is called back one is for forward and refresh these are the three methods which are comes under navigational commands again these three commands we can directly access through driver instance
okay we can access these commands directly through driver instance now let us see how we can use them practically go back to pi champ close it and i will create another python file all right so i'll name it as navigational commands
all right so now let us import the web driver module service module by module and everything so i'll copy the service object all right so now let us open one application first okay so i say driver.get
and here i'm just trying to open you can use any web applications any urls are fine so not only this i'm just taking some samples so this is one application i'm trying to open first time the second time immediately on the same browser window i say driver.get
i'm opening another application like this so now what happens is first time opens the browser and snapdeal.com application will be open on the same browser window the second url also will be open it is basically replaced with this one this is replaced with the new application
okay let's run these two commands first run navigational commands you can just observe here first snapdeal.com is open on the same browser window amazon.com is open right now we are in amazon.com page now i need to go back to my snapdeal page
i just navigate to previous page instead of typing this statement again because browser is already remembered so we no need to type this command one more time simply we can say driver dot driver dot back so this will automatically go to the snap deal page so
this will go to snap d page now again i want to move forward or i want to forward to amazon.com then simply drive a dot forward driver. we are not specifying the urls here we just once you already opened them so we're just navigating backward and forward so here this will go to amazon.com
and if you want to reload the page or if you want to refresh the page simply can say driver dot refresh so this will automatically reload the page okay so this is how we can use so let me just execute and finally i want to quit my browser also i say driver dot quit because i want to close
all browser at a time it will open only one browser window but the process will be created for both because this is another application this is another application even browser also remember two urls so it is better to quit the process so i say driver dot quit now execute [Music]
so launching my first application snapdeal.com and then amazon.com then go go back now again move forward and then finally refreshing the page and browser is closed so these navigations we can control through our automation script
so these commands are comes under navigational commands only three camera it's very easy to remember also once you start using or once you start practicing you can easily remember them back forward refresh so how we can access these methods we can access them through driver instance
directly and close and quit also we can directly access through driver instance and application commands also we can directly access through driver instance only the conditional commands we can access only through web element remember this okay only through web element we can access this
command and rest of the commands we can access only through driver instance okay so these are the four types of application commands conditional commands browser commands navigation commands so before discussing the weight commands i want to discuss a few more or two more important concepts
like find element and find elements what are the differences between find element and find elements there's one topic uh i'm just going to discuss one second thing is how to capture the text from the element okay and in the next session we will discuss about weight commands
because this is having another three types of weight commands we will discuss in detail but before that let me just uh cover two more important topics very important for especially for interview okay you need to understand this so far we have used find element
also we have seen how to use find elements and if i ask the difference between find element and find elements straight forward answer is find element method will return single web element and find elements is a method which will written multiple web browsers so apart from these two
is there any other differences between the find element and find elements that we will discuss now okay so let's go to by champ i'll take one example and show you what are the other differences between find element and find elements we have to have a clarity on this find underscore element
this is one method which we have and other one is find underscore elements so both will take locator as an argument right so look at its x bar link is whatever it is so both will take the locator as an argument but find element find elements see the differences
go back to the pie chart and create one more example most important in interview so listen carefully find element find element versus find elements find element versus find elements okay so let me just
copy some piece of code here importing webdriver service by class and location of my driver service object is created now so let me just open some application here go back to the browser this is the application url
so let me open this through automation script so this is my application you are go back i say driver dot get launching my application this is my application right so now as soon as you launch my application so first let us see the find element okay what are the
different things are available for find element find underscore element is a method find elementor okay so what is the basic understanding we have so far on find element returns a single web element right that is always true so returns single web at any cost it can take
single locator or multiple locator doesn't matter finally it will return only single web element remember that point return single web element always return single web element now let me just show you three different scenarios what are they
in the find element method i will pass the locator which is also pointing to single web element that is one scenario second scenario is i'll use a find element method in which i will pass the locator which is pointing to multiple web elements scenario three i'll use a find element
method in which i will pass the locator of the element which is not available on the web page then how find element method will react okay these are the three different scenarios i will show you for the find element method and find elements method then you can see other differences
between find element and find elements okay so first let us start with a known difference which is find element return the single element find elements be written multiple web elements so forget about find elements for now let us see the three scenarios for find element okay
what is the first scenario is locator matching with the single web element locator matching with the single web element now go back to this application let me search the search store and get the element so this is the element which is pointing to single web element
remember this you can just look at here it is pointing to single web element the locator is pointing to single web element so i'm saying driver dot find underscore element by dot x path with double quotations x path i have written so find element is a method and even locator also
pointing to single web element now i am storing that web element in a variable i said elementor i will say element now this is a single web element so that we can directly perform the action element dot send the keys i can access because if it is single web element then only you will
get the send keys method enable here because the element is a variable which contains a web element so there's a reason as i said element dot automatically send keys method is enabled here this is just a variable okay you can just simply say x y z whatever you can you can give it just
a variable name don't confuse when i say element here okay this is just a variable name and which contains the web elements so because it is a web element we can perform the action directly so it is enable send keys method so we can happily pass some value in it so i can just pass some
value here apple macbook pro 13 so i can just pass some value this is perfectly fine right so let's execute and see because we are using find element and locator also pointing to single web element so no problem in that now you can see it is identify this element and also it is passed the value this
is saying one scenario this we already know it we have find the element with the single locator and return the web element and we can directly perform the action now look at the second scenario the locator matching with the multiple elements suppose this locator is matching with the
multiple web element then what happens okay let me just comment the statements if the locator is matching with multiple web elements then what happens so what i will do is from this application i want to capture the multiple web elements i just want to
write one x path which will capture multiple web elements so let me open this application in this if i just come down to this page there are so many links are available so these are all footer links you can call them as a footer links and i don't want to capture all the links in the page i just
want to capture the links only from the footer section i want to just capture the links only from the footer section like information links customer service link my accounting and followers links how we can do that inspect this only footer section inspect only footer section just
identify like this okay only footer section and if i just look at this and it is basically highlighting this line just little go up like this and you can see class equal to footer you can see right so this is a division tag is there class equal to footer so when highlighting this line
is automatically highlighting entire footer section right again inside this there are two dv's are there again in the first division again so many views are there you can see as soon as i am highlighting each division it is highlighting is a specific section in the footer on the web page
that means what if i open the first division there are another divisions are there again if i go to this division again strong is there that is actually heading part information and if i ins if i expand the url again there are so many li tags here and basically all these are links right
all these are links so if i just look at very high level inside the footer only we want to capture all the links so do we need to really go through each and every individual tags and finally capture the links because i want to capture all the links not a specific link
right so what we can do here is we can just write a simple customized text path i will show you how to do this i say slash i say slash like division i'm just writing the x path till here do class equal to footer okay div and inside this i say at the rate class i'm using attribute called class
what is the value of the class footer section so just execute this x path finding one element what is this one element the footer section itself is one element now inside the footer section i want to access all the links and i can use directx path relative xpath because slash slash will
directly jump into the anchor tags right so we can just keep the middle of element middle there is so many divisor url tags are there inside the ul again list items are there so many things are there but we don't need all those things we just want only links from the footer section
so first we went to the footer section by using this xpath then directly jump into the anchor tags so now we can just observe 23 links are identified 23 links are right exactly links only identifying here on the footer section right so this is how we can just customize our expat now this x path
is exactly pointing to multiple web elements each link is a web element right now remember that point this x path is pointing to multiple web elements now i'm going back and write the locator so still i'm writing the find element only okay driver dot find element by dot x path and specify
the text path now this particular statement will return single web element or multiple web element so the locator is pointing to multiple web elements but outside what is a method we used find element so how it works now so this is going to written first element among suppose let us assume
this is returning multiple web elements how many elements is written basically it is written almost that 23 elements among 23 elements whichever the first element we have here site map that element will be returned because we use only find element only one element will be returned
right so that i can store here element can we perform the action on that element or not we can easily perform the action so i want to get the text of this element i want to know what is that element which is captured by this find element how we will know that just element.text
method we can use text so if you want to capture the text of any element you can use a text element dot text similarly if every text box every link every button is having some name some label on that if you want to capture it you can just use text element dot text so let us print that value i
say print element dot text so this will print you the first element which is it is not printing the element remember guys most of the people will do mistake here element is a kind of an object object we cannot print that object object contains again multiple variables multiple methods object
is an entity which contains a lot of things so if we cannot directly print the object but we cannot extract the values of the object we can call the method from the object so if you consider this element is an object element is a web element object we are extracting
the text value of that object okay we should not print element directly we have to call a method from that object so that we will get the text value of that object let's try to execute this i hope you understand this one and this one because in the first scenario we have past locator
which is pointing to single web elements so anyway it will return the one single web element we perform the action in the second scenario we are passing the locator which is pointing to multiple web elements but still it is returning one web element because we use the find element
because we got the one element we can directly perform the action let's run and see here so now we can just look at here what is an output we got here we just printed site map this statement is printed that so
why it is printed only the text of the first link in the footer page because because it is returning only one web element even though we pass the locator which is matching with the multiple web elements still finally it is identified only one single web element so that
we got the text value of the one single web element i hope everybody is clear here okay now so this is basically printed first link from the footer which is a site mapper okay now i'll show you third scenario this is more interesting
third scenario in the third scenario is what suppose i am using find element i have written one locator here maybe it is a thing uh the locator may point into single element or multiple element doesn't matter but suppose
that element is not available on the web page if the element is not available on the web page then what happens find element method will return the exception no such element exception okay so if the element is not found then find element method will return no such element exception no
such element it's not depending on the locator you can use locator which is pointing to single web element or you can use locator which is pointing to multiple web elements it doesn't matter finally if this locator is not able to find any web element or web elements on the web page then find
element will return no such element exception no such element exception let me show you one example here so let me just try to identify this login link okay inspect this link login go to selector hub so this is a login i'm just using this as a link text okay copy this find that element
driver dot find element find underscore element by dot x path sorry it is not an x path right it is a link text dot link underscore text and passing the link text is it correct value or not this is a correct locator only right and i am storing that in a variable like element i am
storing that element also in a variable i i can call it as a login underscore element now what i will do is i will i can perform some action on this or else no problem you can just leave for now so what i can do is if you want to perform if you want to perform click action on this you can just
take this element perform dot click method you can use like say login underscore element dot clicker fine now understand this so this is perfectly fine right when i execute this you don't see any issue it will identify one element it will return that element and also perform the click action on
the login links as soon as you click on the login now you can see here it is opens a login page here but suppose i'm giving some incorrect locator i'm removing this in now the locator is incorrect so with this locator there is no element available on the web page now
what find element will do find element will return no such element exception so remember guys in interview people may ask you this kind of questions so when you will get the no such element exception or the find element is not able to find the element what is an exception
it will throw then you should be able to answer that so no such element found exception now it is written some exception immediately it is get stopped it is not clicked because it is written in some exception read that exception here in the console window go back
see this no such element exception no such element unable to locate element which element this is the element it is unable to locate the element so when the element is not available when the locator is not matching with any of the elements on the web page it will throw no such element exception
and this is a another big difference between find elements and find element we will see all three scenarios for find elements also okay then you will be able to understand all right so this is these are the three different scenarios we have seen so far right now let us see
the same three scenarios in the find elements also then you will understand the differences clearly now we'll see find elements so we already know find elements is a method which will return some multiple web elements right multiple web elements now the first scenario is what locator is matching
with the single web element let's see this i am using find elements method but internally i will pass only one locator which is matching with one single element now how it is possible observe this take the same example okay in this observe this instead of find element i'm using find elements
now this locator is pointing to single web element what is that element the search box but outside we use the find elements so obviously it will return multiple web elements so now this variable contains how many elements this variable contains how many elements for example
i say elements i i'm just giving a variable as elements now observe this carefully if this method returning single web element then i will able to access the send keys method see this this time i'm not getting send sendiki's method i'm not getting sendiki's method but
here we got the centigrades method because this is returning the single web element so here we are not getting the send keys method because we are not getting the single web element so how it is working now even though the locator is matching with a single web element
find elements method return that element if the locator is matching multiple web elements it will return multiple web elements if this locator is matching with the only single locator or single web element even that element also returned
but that is not that is not written as a web element it is written as a list item that's the difference it is written as a list item because find elements method always written a list collection remember guys find elements always written a list collection whereas find
element always written a web element object list collection object is list object is different web element object is different so if it is written a web element object then we will able to directly access methods send keys but here this is also returning the web element but that
web element is a one of the item in the list collection now what is the type of these elements element is a list collection element is a list collection now how many how many elements are there in this elements list how many elements are there in the element stress only one because
this this locator is pointing to one element only right but how to access that element first of all let's see how many elements it has for that what you will do len of elements i hope you are clear about this method len lenny is a function by which we can count how
many items are there in this list so elements is a list object here elements is not a web element object because find underscore elements always written the list collection or list object but not a web element object if it is a list object we can count how many elements are there right how
many items are there in the list same thing i am doing here let's find out how many it is returning see this it is launching my page and fine so now we can see here one it is returning what is that one one is a one is a element one web element because this locator is pointing to only one
web element only that element is returned as a list item not as a web element as a list item so when i say lenovo elements it is just saying the size basically how many elements are there but what is that element i want to know what is that element i want to know
how we will get that so i have only one element in the elements list how to capture that element how to capture that elements elements of we have to pass the index right index when i say 0 index always start from 0 so when i print like this print off elements of 0 dot text elements of
zero is pointing to element web element which is available in the elements listed got my point let me just give the clarity now so find elements method here which is written in the list actually list collection list means what collection of items now elements so this is actually
elements okay elements is the name of the list now this locator is pointing to one single web element so that element is available as a zero element in the first place so how to access this element now by using element of zero so now this is exactly pointing to the first element now for that element
i want to capture the text or i want to enter the value because it is a text box so i can use one method action method here so now what i will do is i will just use send keys method because it's a text box elements of zero dot send the keys method we will able to access but here we haven't
get the send keys method elements because which is a list collection once you extracted the element from the list collection then we are able to use send keys method so here you can pass this value this is how we need to do one more bracket so now in this statement what exactly we have done sorry
so in this statement what we have done so we are not printing anything just we want to access the element from the elements see this so here we have just counted how many elements this find element is returned but here what we are doing we are accessing the first element in the
elements list and performing the action right so now execute right so now you can see it is enter the same value in the text box okay so this is one scenario so here what we need to understand is find elements method will
not written web element even though the locator is pointing to one single web element it is returning the web element or web elements in the form of lister so again if you want to retrieve them we have to specify the index number retrieve that web element and then perform the action
okay suppose when you pass the locator which is matching with the multiple web elements right so then what happens we see the next scenario locator matching with the multiple web elements so i'm just copying the same thing here
comment it now observe this same thing previously this locator is pointing to one element so we got the size is one this time understand this so this time what i will do is i will pass this locator this is pointing to all
the links in the footer page footer links right but this time how what is the count you will get see same find elements method previously we passed a locator which is pointing to one element so it is retaining only one so length of elements returning only one but this time this locator
is matching with multiple web elements multiple links so all the links will be captured into this elements every link is a web element now how many total links are available in the footer page all those links links will be counted and it will print here so let's execute and see now
[Music] okay now it is done close it now you can see 23 links are available that means 23 web elements are available 23 web elements are available i want to get the first web element just like this i want
to print the first web element i want to see that what you will do simply here take this elements of 0 dot text elements of 0 is representing the first web element in this collection and from that web element i want to extract the text value so when i print this which will get the first element
text value because 23 links are there in the first link whatever the text value is there that will be written so now you can see site map is the first one in the footer page site map is the first one suppose i want to capture the text of all the links all 23 links
so instead of writing this statement 23 times just by changing index number one two three four you can do that but if you have just if you have two to three elements in this you can do that like elements of zero dot text next statement elements of one dot x elements dot
two dot x you can do like this but if you have thirty element fifty element hundred elements it is very difficult to write the same statement multiple times so how we can do that now i want to capture the text value of every element which is captured in this variable for that we need
to write a loop statement so comment this and let me write a loop statement for element in elements loop statement i am writing so what this statement will from the elements first it will take the first element into this variable now here just i am printing the text
of that element the second round of execution it captured another element into this variable and then print the text again third round fourth round so this loop will repeat 23 times and it will capture the text from all 23 elements let's execute now so this time you
will get the link text for all 23 links yes now we can just look at this so first one is a site map from here it is started so these are all the link text which are available in the footer page so this is how just by writing simple for loop we can extract all the text values of every
web element this is the second scenario so find elements with a single locator a locator which is matching with a single element find elements with the locator which is matching with the multiple web elements just to only one difference we need to understand find elements even though it is
matching with the single element that it is also part of the list but it is not a web element now third scenario what is the third scenario locator matching with the element is not available then what happens in case of find element it is true it is thrown no such element exception
but in case of find elements it will not throw any exception it will not throw any error it will not throw any exception just simply return nothing so let me just show you this same thing for find elements element not available then what happens
so let me just say log here find elements i'm using okay i'm not removing this see this i'm just opening this page and i'm getting this into login underscore web here itself which will throw exception actually in case of find element
but in case of find element it will not throw any exception first of all and basically find elements method will return elements in the list collection right so let me just take elements variable and find out the length here length of elements and see how many elements it will return
i say elements returned elements written see if it is really capture the elements it will show you some number how many elements are captured right and if it is not capture suppose if the locator is not matching with any of the elements
in that case it will not throw anything here he will not get any output here let us execute and see here this is another bigger difference between find element and find elements see this whatever locator i have mentioned which is uh not matching with any of the
elements so it is saying simply zero zero elements but it is not thrown any exception not available simply 0 will be written 0 will be written but it is not thrown in exception but in case because white is 0 because this list contains a 0 items if the element is not available
on the page if the find elements method is not able to find the elements or element by using this locator by default list is having zero right no elements if there are no elements in the list by default the zero is there so the same thing it is printing so length of elements is 0
so what is another difference here in case of find element which is returning no such element exception but find elements will not return any exception that is another difference okay so these are the differences between find element and find elements
remember guys find element written one web element at a time find elements method written multiple web elements in the form of list in the form of list again we have to extract each and every web element from the list another difference so in the find element
uh written no such exception if the element is not found but find elements method will not return any exception even though the elements are not found in the webpage okay so this is all about find the elements and find element
okay so now we'll see one more small topic the difference between so far we have seen how to work with the text right what is the text here it will just get the value or text of the element so if you want to extract the text of the element we use element
name dot text many places we have used here right so we have another method also there called get text okay or not get text get attribute value so let me just tell what exactly is text versus get underscore attribute of value most of the people will have confusion on this
let me just explain so far we haven't discussed about this get underscore attribute of value i'll tell you what is this method and later i will compare these two then you will understand the differences okay let's go and create another example
all right so i'll name it as a text versus get attribute okay so now i'm just copying some piece of code and launching this web application so this is the application i'm launching let's look at here
okay so we have to really observe this most important as soon as you launch your application so by default this value is projecting in this input box this is the default value right you can see here administrative store.com by default this value is populating in the text box
suppose i want to clear this value suppose even though if a value already available if you want to use send keys method again what happens is the next value will be just appended like this that becomes a wrong email so before entering the value you have to clear the input box so to clear
the input box what you will do take this element use dot clear method okay so after that i'll tell you what is the text and get text method so let me first get this element inspect this element and go to selector hub and they have just giving some time stamp guys here so within
these seconds you should capture this otherwise it will go off so take this relative x path and find that element here driver dot find element i dot x path specify the x path and this is the element i just want to capture into the variable i'll give some variable name
called email box so i hope this statement is clear to everyone so just finding the element single web element and storing the into variable so once you get the element you can perform the actions right so email box dot clear i can do it will clear the input box similarly email box dot
i can use send keys method and here you can pass anything i say absolutely gmail.com i'm passing i can just pass some value here right so let's execute here first clear the input box and then we pass some value in it
yes now you can see it is already clear and the new value is entered now observe the difference here i clear the input box and then i pass some value here right here what i will do is from the same email box i want to capture the text
because what is the text will do which will basically get the value of the element any web element so earlier we have seen so in the previous example right in the previous example find element method we use the text here for the web
element whatever web element link is captured here we capture the text value of the linker right so similarly what i have done here i capture the web element as an email box and then i'm capturing the text value of the email box we have cleared that email box we pass some value
so now this value is populating on the input box you have to remember that this value is already populating on the input box as soon as we provided it and after that i'm capturing the text so what this will print this time we will see that print so here i am saying a result of result of
text result of text okay input boxes what you are expecting from here what the statement will return we already cleared it then provided the value also now the input box or email box is having some value there right so i'm just want to get the text
of that particular input box so for that what i have done email box.text i am doing so this will return the text of the email box and should print it here okay and then i'm also trying to use one more statement here the result of text is i'm printing
here the result of get underscore attribute is another method we have get underscore attribute of result of get underscore attribute so here i'll say instead of text i'm just saying dot get attribute method i'm using get attribute of value get attribute of value
we'll see the difference okay so my intention is here i just want to capture the text value of the element that's my objective i just want to capture the text value of the elementor so as soon as you see this element if i ask you what is the text value of the element simply you
say this is the text value of the element admin underscore us4.com or abs underscore abc.com so whatever email id you are providing inside the input box you consider that as a text okay similarly if i just if you want to if i ask you to what is the text of this
button if you simply say login is a text value of this button okay similarly suppose i want to get the text value of the email box and here i've used text variable and here i'm using get underscore attribute of value method now we'll see what they will return when i run this code
so this will return two different things see this the new values is already added abc underscore gmail.com now if you observe the the result the first statement text is not returning anything
it's not written anything this time but get underscore attribute is returned abc.gmail.com what does it mean this particular method is printed whatever is displayed on this element so it is basically capture this but this is actually text right but why text is not captured
why get attribute value is captured this white text is not able to capture this so you need to understand the difference between these two most important so what text will do what a get attribute will do when we have to use text when we have to use get attribute
okay remember this so to understand this we need to first go to the page let's go to the page and here we have inspected this element let me open this another tab so let us inspect this element
so initially if i just look at here if i this is a html of input right input is html tag there are different attributes are there so for this element input element do we have in a text somewhere here in a text means what let me tell you here
input is my tag okay suppose here let's say id is there some one two three and a name is also there some xyz and closed closed let's say email i say some label is there email and here input tag is closed let's say this is my html this is my html in this input is a tag
id name are the attributes and their values this is my closing tag what is this email here this is a called inner text remember guys so this is called as a inner text remember this is a inner text which is there in this place after closing here input is a opening so certain number
of attributes are associated with the tag and inside this between greater than and less than the whatever value or text is displayed here this is called as an inner text email is inner text okay now based on this understanding do we have inner text in this or not
so input tag here you have to tell so in this input i this is a starting tag so where it is closed here it is already closed so in this do we see anywhere in a text is there or not in a text in the text is displaying or not somewhere
you can just notice here it's not displayed please respond in the chat window so here input is a tag there are so many attributes are there class attribute value is there auto focus type data val id name mail email area invalid then close it but here in a text is not available
in a text is not available so even i use the text method text variable this will return only in a text of the element remember guys text will always return inner text text is always written in text returns inner text of the element whichever element it is there only inner text will be
returned but for but here for this element for this element we don't have inner text we don't have a inner text so that's the reason it is not returned any value here this is empty value because the text we have to use only if you want to capture the inner text of that element
if the element is not having any inner text in the html it simply return nothing first point remember this so text is always used to get the inner text of the element if inner text means what this is a inner text
most of the times links are having in the text links were having in the text suppose let me identify one link here so in this page do you have any links here i think we don't have any let me just inspect this login okay so now you can just see login in the text is there
for the login in the text is there but if you want to capture this you can use the text you can use a text method but uh if you don't have this inner text like input box if i just go with the input box again here we don't have inner text so we cannot capture the text in the text is not
available so in the case of input box here we don't have inner text here that's the reason we have to always go with the next method called get underscore but still i want to capture this value text is not returning anything but i want to still capture this value
whatever email it is which is displayed on the email box i want to capture it then what you will do you can use one more method called get attribute of value what this method will do we understood what exactly text method will do right so if there
is any inner text just the text will capture the text and will display it simple it can be any element it can be radio button checkbox links drop down input box anything it will just go and get the inner text of the element simple if the inner text is not available returns nothing
same thing is happened in the case of email box just now we have seen but what about get underscore attribute what get underscore attribute will do get underscore attribute method will use to get the value of any attribute of the element for
example i want to get the value of id then i can use get underscore attribute of id that will return 1 2 3 suppose i want to get the value of name attribute simply i can say get underscore attribute of name that will give you xy jet similarly
if you want to capture this email id of this email you can see the value attribute is there value attribute is there so if you want to get this value what i have to write now get underscore attitude of value so when i say get underscore attribute value what this will return this will
exactly return the email id which is displayed on this element so as soon as you change it like this it will also change the html you can see here gmail.com see now in the html automatically value will be changed so here abc and then g ustore.com again you have to inspect that element dynamically
it cannot change see this because as soon as you refresh the new old values again come here okay but dynamically you cannot do here but through automation we can do here as soon as we change the value here see this as soon as you provided the new value when i get get attribute what happened
here it is returning the new value abc gmail.com from where it got this value from where it is returning this value because it is getting the value of value attribute because for this element for input box element there is a value attribute further there is some value which is associated
and that is a value which is returned here okay so got the difference guys so text is always written in the text of the element if it is available if it is not available returns nothing get attribute of value or get attribute is a method which will return the value of any attribute not only value
which is basically returns returns value of any attribute of web element web element if you pass id here id value will be written if i pass a name here name value will be written if i pass class here class value will be written if i pass value then value of the value will be written
okay so now in this particular case input in case of input box there is no in that text so it is retaining nothing so it is printed and nothing none or you can say nothing but it is having some value attribute which is having some email id associated with the value
so this is printed a b is underscore gmail.com in case of input box we have seen two scenarios for input box there is no inner text that's the reason text is returning nothing for the same input box there is a value associated with that so we will able to
get that value by using get attitude now the same thing i will replicate for the login button then we will see because the login is having in the text and there is no value attribute here right now we'll see that so let's get the login element now let me open another tab
i'll finish another five minutes so now inspect the login element all right so get the x path of the element login element so these are element which is given x path is given let me use it so i say driver dot find element by dot x path specify the text path
i'm not doing anything and just get that element i say button get that element into a variable i say button now observe this so i say button dot text okay i'm printing this button dot text and the second one is i'm printing button dot get attribute which attribute value want
so we don't have value attribute only type is there class either xpath is there but still even if you use value it will not return anything because value attribute is not at all available right not at all available so let me just write simple message also so here i say result of text
result of text and here i'll say result of get attribute in case of button so we have done this for input box earlier now we are doing for we are doing for button okay let's comment this now i capture the law button element for that i'm using text so now what is an
expected value here will you get a value for the text or not yes why because the button is having inner text here login is in the text so this time we will get the value for the text but we will get anything for this get attribute previously we is the reverse we haven't get any
value for the text but we got the value from get attribute so now execute and see the output done so now you can see here this is a text value of the button but you don't have value attribute for that element so not at all there here what valued so it is returning nothing
but instead of value when i say some other attribute suppose available attribute let us say type is available so let me just say type here now we'll see okay now you can see here type is submit exactly there the same value is there in
our application exactly submitted so remember guys so text method returns in the text of the element whereas get attribute will return value of any attribute of the web element simple difference and when we have to use the text if i want to capture the inner text of element
then use text and if you want to capture the value of any attribute of the web element then go and use get attribute and both we will able to access through web element one web element only we have to access this method not from the driver instance we should not
use driver.txt or driver dot get teleport no web element dot text web element dot get art okay so remember this most important and i'll stop here for today's session so far we have discussed four different type of commands application commands comma conditional commands
browser commands and navigational commands so weight commands we will discuss in the next session along with them we also discussed about difference between find element and find elements and three different aspects i have shown you and another thing is difference between text
and get underscore attribute when we have to use a text when we have to use get underscore attribute okay so practice these items for today and tomorrow we will discuss a few more items
You can use the driver.title property to get the current page title and driver.current_url to fetch the URL of the current page. For example, after navigating to a page with driver.get('https://example.com'), you can print these values directly to verify the loaded page.
The close() method closes the currently focused browser window but keeps the WebDriver session running if multiple windows are open. In contrast, quit() terminates the entire WebDriver session and closes all associated browser windows. Use close() when you want to shut just one window and quit() to end your automation session entirely.
Selenium provides conditional commands like is_displayed() to check if an element is visible on the page, and is_enabled() to verify if the element is interactable. Using these checks before performing actions ensures your scripts are robust and avoid exceptions caused by interacting with unavailable or disabled elements.
Use find_element when you expect a single unique element matching your locator; it returns the first matched element or throws an exception if none are found. Use find_elements when you need to retrieve multiple elements; it returns a list which can be empty if no elements match, allowing safe iteration without exceptions.
The .text property retrieves the visible inner text of an element (like labels or links) but returns empty for input fields since they typically don't have inner text. To get the content of input fields or elements with a value attribute, use .get_attribute('value'), which fetches the attribute's current value. Choose the method based on the element type for accurate text extraction.
These navigation commands simulate user actions with browser history: back() moves to the previous page, forward() moves to the next page if you have navigated back, and refresh() reloads the current page. Using these commands allows your automation to control flow dynamically, testing behaviors like redirections and page reloads effectively.
Verifying element states using commands like is_displayed(), is_enabled(), and is_selected() helps ensure that your automation interacts only with elements that are ready and appropriate for action. This prevents errors like interacting with hidden or disabled elements and improves script stability and reliability during test execution.
Keep this summary
Save it to LunaNotes and it becomes a real note in your library — editable, searchable, and ready to turn into flashcards or a diagram. Free to start.
Save to LunaNotesOr summarise for another video.
This summary and transcript were automatically generated using AI with the Free YouTube Transcript Summary Tool by LunaNotes.
Related summaries
Comprehensive Selenium WebDriver Tutorial: Setup and Basic Automation
This detailed guide introduces Selenium WebDriver, covering its architecture, setup methods, and a basic automation test case. Learn how to configure your environment using manual and Maven approaches, understand WebDriver's role as a Java interface and API, and write your first automated browser test.
Comprehensive Software Testing Tutorial: Manual to Selenium Automation
This tutorial covers all essential aspects of software testing, from fundamental concepts and software development lifecycle models to practical automation using Selenium. Learn about testing principles, defect management, testing methods and levels, documentation, and effective use of Selenium locators and waits to automate web testing.
Exploring Puppeteer and Headless Browsers: A Comprehensive Guide
This video provides an in-depth look at Puppeteer, a powerful Node.js library for controlling headless browsers. Learn about the installation process, basic commands, and advanced features such as web scraping, automated testing, and image downloading.
Mastering Java: Understanding Conditional Statements for Beginners
Dive into Java's conditional statements, including 'if', 'switch', and 'break', to enhance your programming skills.
Unlocking the Unlimited Power of Cursor: Boost Your Productivity!
Discover how to harness Cursor for ultimate productivity, from controlling apps to optimizing workflows!
Most viewed summaries
A Comprehensive Guide to Using Stable Diffusion Forge UI
Explore the Stable Diffusion Forge UI, customizable settings, models, and more to enhance your image generation experience.
Kolonyalismo at Imperyalismo: Ang Kasaysayan ng Pagsakop sa Pilipinas
Tuklasin ang kasaysayan ng kolonyalismo at imperyalismo sa Pilipinas sa pamamagitan ni Ferdinand Magellan.
Mastering Inpainting with Stable Diffusion: Fix Mistakes and Enhance Your Images
Learn to fix mistakes and enhance images with Stable Diffusion's inpainting features effectively.
Pamamaraan at Patakarang Kolonyal ng mga Espanyol sa Pilipinas
Tuklasin ang mga pamamaraan at patakaran ng mga Espanyol sa Pilipinas, at ang epekto nito sa mga Pilipino.
How to Install and Configure Forge: A New Stable Diffusion Web UI
Learn to install and configure the new Forge web UI for Stable Diffusion, with tips on models and settings.
Found this summary useful?
Take it with you. One click puts it in your own LunaNotes library.
Save to LunaNotes