What Is Software Testing?
What Is Software Testing?
0) and for
that you have jdk higher version.
Software Testing
What is Software Testing?
• Software Testing is the process of identifying the correctness and quality of software programs. The purpose is
to check whether the software satisfies the specific requirements, needs, and expectations of the customer. In
other words, testing is executing a system or application in order to find software bugs, defects or errors. The
job of testing is to find out the reasons for application failures so that they can be corrected according to
requirements.
• Software testing can be stated as the process of verifying and validating that a software or application is
bug free, meets the technical requirements as guided by it’s design and development and meets the user
requirements effectively and efficiently with handling all the exceptional and boundary cases.
• The process of software testing aims not only at finding faults in the existing software but also at finding
measures to improve the software in terms of efficiency, accuracy and usability. It mainly aims at
measuring specification, functionality and performance of a software program or application.
Verification Validation
Verification addresses the concern: "Are you Validation addresses the concern: "Are you
building it right?" building the right thing?"
Ensures that the software system meets all the Ensures that the functionalities meet the intended
functionality. behavior.
Verification takes place first and includes the Validation occurs after verification and mainly
checking for documentation, code, etc. involves the checking of the overall product.
It has static activities, as it includes collecting It has dynamic activities, as it includes executing
reviews, walkthroughs, and inspections to verify a the software against the requirements.
software.
1. Manual Testing: Manual testing includes testing a software manually, i.e., without using any
automated tool or any script. In this type, the tester takes over the role of an end-user and
tests the software to identify any unexpected behavior or bug. There are different stages for
manual testing such as unit testing, integration testing, system testing, and user acceptance
testing
Testers use test plans, test cases, or test scenarios to test a software to ensure the
completeness of testing. Manual testing also includes exploratory testing, as testers explore
the software to identify errors in it.
Test Case
Test Case ID: BU_001 Test Designed by: <Name>
Test Title: Test the Login Functionality in Banking Test Execution date: <Date>
Dependencies:
Expected Status
Step Test Steps Test Data Actual Result Notes
Result (Pass/Fail)
Credential
Provide valid
2 User= example@gmail.com can be As Expected Pass
username
entered
Credential
Provide valid
3 Password: 1234 can be As Expected Pass
password
entered
Click on Login User logged
4 User logged Pass
button successfully
2. Automation Testing: Automation testing, which is also known as Test Automation, is when
the tester writes scripts and uses another software to test the product. This process involves
automation of a manual process. Automation Testing is used to re-run the test scenarios that
were performed manually, quickly, and repeatedly.
Apart from regression testing, automation testing is also used to test the application from load,
performance, and stress point of view. It increases the test coverage, improves accuracy, and
saves time and money in comparison to manual testing.
What is Selenium
Selenium is one of the most widely used open source Web UI (User Interface) automation testing suite.It
was originally developed by Jason Huggins in 2004 as an internal tool at Thought Works. Selenium
supports automation across different browsers, platforms and programming languages.
Selenium can be easily deployed on platforms such as Windows, Linux, Solaris and Macintosh. Moreover, it
supports OS (Operating System) for mobile applications like iOS, windows mobile and android.
Selenium supports a variety of programming languages through the use of drivers specific to each
language.Languages supported by Selenium include C#, Java, Perl, PHP, Python and Ruby.Currently,
Selenium Web driver is most popular with Java and C#. Selenium test scripts can be coded in any of the
supported programming languages and can be run directly in most modern web browsers. Browsers
supported by Selenium include Internet Explorer, Mozilla Firefox, Google Chrome and Safari.
Selenium can be used to automate functional tests and can be integrated with automation test tools such
as Maven, Jenkins, & Docker to achieve continuous testing. It can also be integrated with tools such
as TestNG, & JUnit for managing test cases and generating reports.
Selenium IDE
Selenium IDE (Integrated Development Environment) is a tool that helps you develop your Selenium
test cases. It’s an easy-to-use Chrome and Firefox extension and is generally the most reliable
method to develop test cases. It records users’ actions in the browser for you, using the existing
Selenium commands, with parameters defined by the context of the web element. This is not only a
time-saver but also an excellent way of learning Selenium script syntax. Previously known as
Selenium Recorder, Selenium IDE was initially created by Shinya Kasatani, of Japan and contributed
to the Selenium project in 2006.
It was introduced as a Firefox plugin for faster creation of test cases. As it was a Firefox extension, it
could automate the browser through a record-and-play feature providing autocompletion support and
the ability to move commands around quickly.
Scripts are recorded in a special test scripting language called Selenese for Selenium. Selenese
comes up with commands for carrying out actions in a web browser and restoring data from the
resulting pages.
The advantage of Selenium IDE is that the tests recorded via the plugin can be exported in different
programming languages like Java, Ruby, Python, etc.
Selenium RC (Remote Control)
Let me first tell you that Selenium Core was the first version. But with that version, testers had to
install both Selenium (a JavaScript program) and the webserver containing the web application being
tested on their local systems so that they would belong to the same domain.
Then, another ThoughtWorks’ engineer, Paul Hammant decided to create a server that will act as an
HTTP proxy to trick the browser into believing that Selenium Core and the web application being
tested belong to the same domain, thus making RC a two-component tool.
• Selenium RC Server
• Selenium RC Client (Library containing the programming language code)
• Java
• C#
• PHP
• Python
• Perl
• Ruby
Selenium Grid
Selenium Grid is a testing tool that lets you run your tests on various machines against different
browsers. It is part of the Selenium suite that specializes in running multiple tests across different
browsers, operating systems, and machines. You can connect to it with Selenium Remote Control by
stating the browser version, browser, and operating system as per your choice. You will be able to
specify these values through Selenium Remote Control capabilities. With Selenium Grid, one server
makes a move as a hub. Tests communicate to the hub to get access to browser instances. The hub
has a list of servers that provide access to browser instances (WebDriver nodes) and lets tests use
these instances.
Selenium Grid allows parallel testing and also allows managing different browser versions and
browser configurations centrally (instead of in each individual test).
There are multiple online platforms that provide an online Selenium Grid that you can access to run
your Selenium automation scripts. For example, you can use LambdaTest.
Selenium Grid has more than 2,000 browser environments over which you can run your tests and
truly automate cross-browser testing.
Selenium WebDriver
Founded by Simon Stewart in 2006, ThoughtWorks consultant in Australia. Selenium WebDriver was
the first cross-platform testing framework that would control the browser at the OS level. Selenium
WebDriver is a successor to Selenium RC. Selenium WebDriver accepts commands (sent in
Selenium or via a Client API) and sends them to a browser.
This is implemented through a browser-specific driver, which sends commands to a browser and
retrieves the results. Each driver launches and accesses a browser application. Different WebDrivers
are:
Step 1: Download Java JDK from the link provided below and then click on the Oracle
JDK Download button
https://www.oracle.com/technetwork/java/javase/downloads/index.html
Click on the radio button, Accept License Agreement, and download the .exe file related to your
OS type
Step 2: Open the downloaded execution file, and click on Next
Step 3: Select Developers Tools and click on Next, and you will be directed to the below screen.
It will take a few moments to set up JDK in your system
Step 4: Click on Close to complete the set up
Before moving ahead, you need to add the environment variables to the path as follows.
Step 5: Go to local C drive > Program Files > Java > jdk-12.0.1 > bin
Step 6: Copy the path as shown above
Step 7: Go to Control Panel > System and Security > System > Advanced system
settings > System Properties
Step 8: Click on Environment Variables as shown above and the below window pops up in
which you will perform the following steps:
Step 1: Go to the Eclipse download page (the recent one is Eclipse Installer 2019-06 R), with this
link: https://www.eclipse.org/downloads/
Step 2: Click on Download 64 bit. You would land on a page as shown below:
This download comes as a ZIP file named "selenium-3.14.0.zip". For simplicity, extract
the contents of this ZIP file on your C drive so that you would have the directory
"C:\selenium-3.14.0\". This directory contains all the JAR files that we would later
import on Eclipse.
1. Project Name
2. Location to save project
3. Select an execution JRE
4. Select layout project option
5. Click on Finish button
4. In this step,
5. Create a new Java class under newpackage by right-clicking on it and then selecting-
New > Class, and then name it as "MyClass". Your Eclipse IDE should look like the image
below.
When you click on Class, a pop-up window will open, enter details as
In this step,
When you click on "Add External JARs.." It will open a pop-up window. Select the JAR
files you want to add.
After selecting jar files, click on OK button.
6. Finally, click OK and we are done importing Selenium libraries into our project.
Different Drivers
A driver server is different for each browser. For example, Internet Explorer has its own
driver server which you cannot use on other browsers. Below is the list of driver servers
and the corresponding browsers that use them.
Chrome- https://sites.google.com/a/chromium.org/chromedriver/
Example-1
import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.firefox.FirefoxDriver;
//comment the above line and uncomment below line to use Chrome
import org.openqa.selenium.chrome.ChromeDriver;
public class PG1 {
/*
* compare the actual title of the page with the expected one and print
* the result as "Passed" or "Failed"
*/
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
//close browser.
driver.close();
}
Explaining the code
Importing Packages
To get started, you need to import following two packages:
For convenience, we saved the Base URL and the expected title as variables.
Get Current URL Command – How to read the URL of the Webpage in Selenium?
getCurrentUrl(): This method fetches the string representing the Current URL which is opened in
the browser. Accepts nothing as a parameter and returns a String value.
As the return type is String value, the output must be stored in String object/variable.
String CurrentUrl = driver.getCurrentUrl();
Get Page Source Command – How to read the page source of the WebPage in Selenium?
getPageSource(): This method returns the Source Code of the page. Accepts nothing as a parameter and
returns a String value.
As the return type is String value, the output must be stored in String object/variable.
String PageSource = driver.getPageSource();
Navigate:-
How to Navigate to URL or How to open a webpage in Selenium Browser?
to(String arg0) : void – This method Loads a new web page in the current browser
window. It accepts a String parameter and returns nothing.
driver.navigate().to(appUrl);
example- driver.navigate().to("http://www.DemoQA.com");
It does exactly the same thing as the driver.get(appUrl) method. Where appUrl is
the website address to load. It is best to use a fully qualified URL.
Forward
How to browser Forward in Selenium Browser?
forward() : void – This method does the same operation as clicking on the Forward
Button of any browser. It neither accepts nor returns anything.
driver.navigate().forward();
example- driver.navigate().forward();
Takes you forward by one page on the browser’s history.
Back
How to browse backward in Selenium Browser?
back() : void – This method does the same operation as clicking on the Back
Button of any browser. It neither accepts nor returns anything.
driver.navigate().back();
example- driver.navigate().back ();
Takes youback by one page on the browser’s history.
Refresh
How to Refresh Selenium Browser?
refresh() : void – This method Refresh the current page. It neither accepts nor
returns anything.
driver.navigate().refresh();
Practice Exercise – 1
1. Launch a new Chrome browser.
2. Open bmefcolleges.edu.in
3. Get Page Title name and Title length
4. Print Page Title and Title length on the Eclipse Console.
5. Get Page URL and verify if it is a correct page opened
6. Get Page Source (HTML Source code) and Page Source length
7. Print Page Length on Eclipse Console.
8. Close the Browser.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
System.setProperty("webdriver.chrome.driver", driverExecutablePath);
driver.get(url);
if (actualUrl.equals(url)){
else {
System.out.println("Verification Failed - An incorrect Url is opened.");
//In case of Fail, you like to print the actual and expected URL for the record purpose
//Closing browser
driver.close();
// Refresh browser
driver.navigate().refresh();
// Close browser
driver.close();
}
}
2.Selenium WebDriver Commands
• Browser Commands
• Navigation Commands
• WebElement Commands
• FindElement and FindElements Command
• CheckBox & Radio Button Operations
• DropDown & Multiple Select Operations
• Handle Dynamic WebTables in Selenium Webdriver
Browser Commands
The very basic browser operations of WebDriver include opening a browser; perform few tasks
and then closing the browser.
1. Get Command
Method:
get(String arg0) : void
this method loads a new web page in the existing browser window. It accepts String as
parameter and returns void.
Example:
driver.get("www.bmusurat.ac.in");
getTitle(): String
this method fetches the title of the current web page. It accepts no parameter and returns a String.
Example:
this method fetches the string representing the Current URL of the current web page. It accepts nothing as parameter and returns a
String value.
Example:
this method returns the source code of the current web page loaded on the current browser. It accepts nothing as parameter and
returns a String value.
Example:
5. Close Command
Method:
close(): void
terminates the current browser window operating by WebDriver at the current time. If the current window is the only window
operating by WebDriver, it terminates the browser as well. This method accepts nothing as parameter and returns void.
Example:
driver.close();
6. Quit Command
Method:
quit(): void
terminates all windows operating by WebDriver. It terminates all tabs as well as the browser itself. It accepts nothing as parameter
and returns void.
Example:
driver.quit();
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
//Closing browser
driver.close();
}
}
Navigation Commands
WebDriver provides some basic Browser Navigation Commands that allows the browser to move backwards or forwards in
the browser's history.
1. Navigate To Command
Method:
to(String arg0) : void
this method loads a new web page in the existing browser window. It accepts String as parameter and returns void.
driver.navigate().to("www.javatpoint.com");
Note: The get command (driver.get(URL);) which lies in the browser commands section does the same function as the navigate
command
2. Forward Command
Method:
to(String arg0) : void
this method enables the web browser to click on the forward button in the existing browser window. It neither accepts anything nor
returns anything.
driver.navigate().forward();
3. Back Command
Method:
back() : void
In WebDriver, this method enables the web browser to click on the back button in the existing browser window. It neither
accepts anything nor returns anything.
driver.navigate().back();
4. Refresh Command
Method:
refresh() : void
this method refresh/reloads the current web page in the existing browser window. It neither accepts anything nor returns anything.
The respective command that takes you back by one page on the browser's history can be written as:
driver.navigate().refresh();
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
// Launch Website
driver.navigate().to("https://www.testandquiz.com/selenium/testing.html");
//Refresh browser
driver.navigate().refresh();
//Closing browser
driver.close();
}
}
WebElement Commands
1. Clear Command
Method:
clear() : void
Command:
element.clear();
2. Sendkeys Command
Method:
sendKeys(CharSequence? KeysToSend) : void
Command:
element.sendKeys("text");
3. Click Command
Method:
click() : void
Command:
element.click();
Code snippet:
WebElement element = driver.findElement(By.linkText("javaTpoint"));
element.click();
//Or can be written as
driver.findElement(By.linkText("javaTpoint")).click();
4. IsDisplayed Command
Method:
isDisplayed() : Boolean
Command:
element.isDisplayed();
Code snippet:
5. IsEnabled Command
Method:
isEnabled() : Boolean
Command:
element.isEnabled();
Code snippet:
WebElement element = driver.findElement(By.id("UserName"));
boolean status = element.isEnabled();
//Or can be written as
boolean staus = driver.findElement(By.id("UserName")).isEnabled();
//Or can be used as
WebElement element = driver.findElement(By.id("userName"));
boolean status = element.isEnabled();
// Check that if the Text field is enabled, if yes enter value
if(status){
element.sendKeys("javaTpoint");
}
6. IsSelected Command
Method:
isSelected() : Boolean
Command:
element.isSelected();
Code snippet:
7. Submit Command
Method:
submit() : void
Command:
element.submit();
Code snippet:
WebElement element = driver.findElement(By.id("SubmitButton"));
element.submit();
//Or can be written as
driver.findElement(By.id("SubmitButton")).submit();
8. GetText Command
Method:
getText() : String
Command:
element.getText();
Code snippet:
WebElement element = driver.findElement(By.xpath("anyLink"));
String linkText = element.getText();
9. GetTagName Command
Method:
getTagName() : String
Command:
element.getTagName();
Code snippet:
Command:
element.getCssValue();
Code snippet:
WebElement element = driver.findElement(By.id("SubmitButton"));
String attValue = element.getAttribute("id"); //This will return "SubmitButton"
Command:
element.getSize();
Code snippet:
WebElement element = driver.findElement(By.id("SubmitButton"));
Dimension dimensions = element.getSize();
System.out.println("Height :" + dimensions.height + "Width : "+ dimensions.width);
Command:
element.getLocation();
Code snippet:
WebElement element = driver.findElement(By.id("SubmitButton"));
Point point = element.getLocation();
System.out.println("X cordinate : " + point.x + "Y cordinate: " + point.y);
Locators
The method findElement() takes one parameter which is a locator to the element. Different
locators like By.id(), By.name(), By.xpath(), By.CSSSelector() etc. locate the elements in the page
using their properties like`````` id, name or path, etc.
locate the "Emailaddress" text field using the id locator and the "Password "field using the name
locator.
1. Email text field is located by Id
2. Password field is located by name
Buttons
The buttons can be accessed using the click() method
driver.get("www.javatpoint.com")
9. Closing Browser
driver.close();
10. Closing Browser and other all other windows associated with the driver
driver.quit();
// Launch Website
driver.navigate().to("https://www.testandquiz.com/selenium/testing.html");
// Fetch the text "This is sample text." and print it on console
// Use the class name of the div to locate it and then fetch text using getText() method
String sampleText = driver.findElement(By.className("col-md-12")).getText();
System.out.println(sampleText);
// Use the linkText locator method to find the link and perform click using click() method
driver.findElement(By.linkText("This is a link")).click();
Step 1
Step 2
Declare the drop-down element as an instance of the Select class. In the example below,
we named this instance as "drpCountry".
Step 3
We can now start controlling "drpCountry" by using any of the available Select methods.
The sample code below will select the option "ANTARCTICA."
Selecting Items in a Multiple SELECT elements
We can also use the selectByVisibleText() method in selecting multiple options in a multi
SELECT element. As an example, we will take http://jsbin.com/osebed/2 as the base URL.
It contains a drop-down box that allows multiple selections at a time.
The code below will select the first two options using the selectByVisibleText() method.
Select Class in Selenium
Models a SELECT tag, providing helper methods to select and deselect options. Select is a class that
is provided by Selenium to perform multiple operations on DropDown object and Multiple Select
objects. This class can be found under the Selenium’s Support.UI.Select package. As Select is also
an ordinary class, so it’s object is also created by a New keyword with regular class creation syntax.
Select oSelect = new Select());
The above code will generate compile-time error in Eclipse, as Select() is asking for constructor. Bring the
cursor over Select(), Eclipse will populate a suggestion.
It clearly says that Select is asking for an element type object for its constructor. The code will be:
selectByVisibleText
selectByVisibleText(String arg0) : void – It is very easy to choose or select an option given under
any dropdowns and multiple selection boxes with selectByVisibleText method. It takes a parameter of
String which is one of the Value of Select element and it returns nothing.
Command – oSelect.selectByVisibleText(“text”);
Example – Refer the above Screen shot of YEAR Drop Down*
Code – To select the value 2010.
Select oSelect = new Select(driver.findElement(By.id("yy_date_8")));
oSelect.selectByVisibleText("2010");
selectByIndex
selectByIndex(int arg0) : void – It is almost the same as selectByVisibleText but the only difference
here is that we provide the index number of the option here rather the option text. It takes a
parameter of int which is the index value of Select element and it returns nothing.
Command – oSelect.selectByIndex(int);
Example – Refer the above Screen shot of YEAR Drop Down*
Code – To select the value 2010 using index.
oSelect.selectByIndex(4);
selectByValue
selectByValue(String arg0) : void –It is again the same as what we have discussed earlier, the only
difference in this is that it asks for the value of the option rather than the option text or index. It takes
a parameter of String which is on of the value of Select element and it returns nothing.
Command – oSelect.selectByValue(“text”);
Example – Refer the above Screen shot of YEAR Drop Down*
Code – To select the value 2014.
oSelect.selectByValue("2014");
getOptions
getOptions( ) : List<WebElement> –This gets the all options belonging to the Select tag. It takes no
parameter and returns List<WebElements>.
Command – oSelect.getOptions();
Sometimes you may like to count the element in the dropdown and multiple select box, so that you
can use the loop on Select element.
Example – Refer the above Screen shot of YEAR Drop Down*
Code – To get the Count of the total elements inside SELECT.
DeSelect Methods
The way we select different values of DropDown & Multi Select, the same way we can
also deselect the values. But the only challenge in these methods are they do not work
for DropDown and only work for Multi Select elements.
In case you want to deselect any pre-selected option, that can be done with either deselectAll(),
deselectByIndex, deselectByValue and deselectByVisibletext.
deselectAll( ) : void – Clear all selected entries. This is only valid when the SELECT supports
multiple selections.
Command – oSelect.deselectAll;
deselectByIndex(int arg0) : void –Deselect the option at the given index.
Command – oSelect.deselectByIndex;
deselectByValue(String arg0) : void –Deselect all options that have a value matching the
argument.
Command – oSelect.deselectByValue;
deselectByVisibleText(String arg0) : void – Deselect all options that display text matching the
argument.
Command – oSelect.deselectByVisibleText
isMultiple
isMultiple( ) : boolean – This tells whether the SELECT element support multiple selecting options
at the same time or not. This accepts nothing but returns boolean value(true/false).
Command – oSelect.isMultiple();
This is done by checking the value of the “multiple” attribute.
Example – Refer the above Screen shot of MULTI SELECT for multiple attribute*
// Or can be used as
oSelect.selectByVisibleText(text)
oSelect.selectByVisibleText(text)
// Or can be used as
oSelect.selectByValue(value)
oSelect.selectByValue(value)
Practice Exercise -1 (Drop Down Box/List)
1. Launch new Browser
2. Open “http://toolsqa.com/automation-practice-form/”
3. Select ‘Continents’ Drop down ( Use Id to identify the element )
4. Select option ‘Europe’ (Use selectByIndex)
5. Select option ‘Africa’ now (Use selectByVisibleText)
6. Print all the options for the selected drop down and select one option of your choice
7. Close the browser
package automationFramework;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class DropDownCommands {
public static void main(String[] args) throws InterruptedException {
// Create a new instance of the FireFox driver
WebDriver driver = new FirefoxDriver();
// Step 6: Print all the options for the selected drop down and select
one option of your choice
// Get the size of the Select element
List<WebElement> oSize = oSelect.getOptions();
int iListSize = oSize.size();
package automationFramework;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
// Step 6: Print and select all the options for the selected Multiple
selection list.
List<WebElement> oSize = oSelect.getOptions();
int iListSize = oSize.size();
1. Static tables: Data is static i.e. Number of rows and columns are fixed.
2. Dynamic tables: Data is dynamic i.e. Number of rows and columns are NOT fixed.
1. Static tables: Data is static i.e. Number of rows and columns are fixed.
2. Dynamic tables: Data is dynamic i.e. Number of rows and columns are NOT fixed.
Below is an example of a dynamic table of Sales. Based on input date filters, number of
rows will get altered. So, it is dynamic in nature.
Web elements are nothing but HTML elements like textbox, dropdowns radio buttons,
submit buttons, etc. These HTML elements are written with start tag and ends with
an end tag.
For Example,
Step 2) Right click on web element whose x-path is to be fetched. In our case, right click
on "Company" Select Inspect option. The following screen will be shown -
Step 3) Right Click on highlighted web element > Select Copy -> Copy x-path option.
Step 4) Use the copied X-path "//*[@id="leftcontainer"]/table/thead/tr/th [1]" in Selenium
WebDriver to locate the element.
import java.text.ParseException;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
Code Explanation:
• Here we have first declared Web Driver object "wd" &initialized it to chrome driver.
• We use List <WebElement> to total number of columns in "col".
• findElements commands returns a list of ALL the elements matching the specified
locator
• using findElements and X-path //*[@id=\"leftcontainer\"]/table/thead/tr/th we get all
the columns
• Similarly, we repeat the process for rows.
Code Explanation:
Output:
additional example:
https://www.guru99.com/handling-dynamic-selenium-webdriver.html
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
driver = webdriver.Chrome()
# URL of website
url = "https://www.google.com/"
get_title = driver.title
driver.get(url)
get_title = driver.title
else {
4.1. Locating by Id
<html>
<body>
<form id="loginForm">
</form>
</body>
<html>
login_form = driver.find_element_by_id('loginForm')
4.2. Locating by Name
<html>
<body>
<form id="loginForm">
</form>
</body>
<html>
username = driver.find_element_by_name('username')
password = driver.find_element_by_name('password')
<form id="loginForm">
</form>
</body>
<html>
login_form = driver.find_element_by_xpath("//form[1]")
login_form = driver.find_element_by_xpath("//form[@id='loginForm']")
1. Absolute path (would break if the HTML was changed only slightly)
2. First form element in the HTML
3. The form element with attribute named id and the value loginForm
username = driver.find_element_by_xpath("//form[input/@name='username']")
username = driver.find_element_by_xpath("//form[@id='loginForm']/input[1]")
username = driver.find_element_by_xpath("//input[@name='username']")
1. First form element with an input child element with attribute named name and the
value username
2. First input child element of the form element with attribute named id and the
value loginForm
3. First input element with attribute named ‘name’ and the value username
clear_button = driver.find_element_by_xpath("//input[@name='continue'][@type='button']")
clear_button = driver.find_element_by_xpath("//form[@id='loginForm']/input[4]")
1. Input with attribute named name and the value continue and attribute named type and
the value button
2. Fourth input child element of the form element with attribute named id and
value loginForm
<body>
<a href="continue.html">Continue</a>
<a href="cancel.html">Cancel</a>
</body>
<html>
continue_link = driver.find_element_by_link_text('Continue')
continue_link = driver.find_element_by_partial_link_text('Conti')
<body>
<h1>Welcome</h1>
</body>
<html>
heading1 = driver.find_element_by_tag_name('h1')
<html>
<body>
</body>
<html>
content = driver.find_element_by_class_name('content')
4.7. Locating Elements by CSS Selectors
<html>
<body>
</body>
<html>
content = driver.find_element_by_css_selector('p.content')
Inspecting elements in web browsers