Posts

Showing posts from 2022

Reading an Excel File and Submitting a Web Form Using Selenium Java

Image
Pre-requisites: geckodriver.exe maven dependencies for apache poi & Selenium <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.1.1</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.poi/poi --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>5.2.2</version> </dependency> This automation process is divided into two parts: Reading from an Excel file  WebForm Automated Filling & Submission Reading an MS Excel File Using Apache POI: Apache POI is an open-source java library developed and distributed by Apache Software Foundation to design and modify MS Off

How to Clear Cache in Chrome Using Selenium Webdriver Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using chromedriver  because Selenium 3 enables chrome driver as the custom WebDriver implementation for the Chrome browser. Pre-requisites: chromedriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: The following 6 steps will automate the process: Set webdriver.gecko.driver and its' path as a system property. Set the firefox diver. Typecast web driver as Javascript executor.  Browse the website. Get a clear cache button using the Javascript path. Execute the following script to execute and hit click: return document.querySelector("body > settings-ui").

How to Take a Screenshot Selenium Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using geckodriver because Selenium 3 enables geckodriver as the default WebDriver implementation for Firefox. Pre-requisites: geckodriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: it takes 4 simple to take a screenshot: Set webdriver.gecko.driver and its' path as a system property. Set the firefox diver and browse to the website. Convert webdriver object to TakeScreenshot . Use the built-in function to get screenshot and save as file. Let’s see all the above steps in the code. We will use getScreenshotAs(OutputType>X< Target) function to take screenshot. import org.apac

How to Handle Modal Dialog Box in Selenium Webdriver Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using geckodriver  because Selenium 3 enables geckodriver as the default WebDriver implementation for Firefox. Pre-requisites: geckodriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: It's a 4 steps process: Set webdriver.gecko.driver and its' path  as a system property. Set the firefox diver and browse to the website link. Get the accept button from dialog box as Web element using webdriver.findElement() function and CSS selector. Click the button to push the modal dialog box away. Let’s see all the above steps in the code. We will use webelement.click(

How to Select Checkbox in Selenium Webdriver Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using geckodriver because Selenium 3 enables geckodriver as the default WebDriver implementation for Firefox. Pre-requisites: geckodriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: it's a 4 steps process: Set webdriver.gecko.driver and its' path as a system property. Set the firefox diver and browse to the website. Get all checkbox flex elements as Web elements using webdriver.findElements() function and CSS selector. Iterate over all these elements and get the desired checkbox and then hit click. Let’s see all the above steps in the code. We will use Webelment.click() fun

How to Scroll Down a Page in Selenium Webdriver Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using geckodriver  because Selenium 3 enables geckodriver as the default WebDriver implementation for Firefox. Pre-requisites: geckodriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: it's a 6 steps process: Set webdriver.gecko.driver and its' path as a system property. Set the firefox diver. Typecast web driver as Javascript executor.  Browse the website. Set x and y coordinates for scrolling. x: Horizontal scroll  y: Vertical scroll  +ve: scroll up  -ve: scroll down Execute the script using the javascript executor. Let’s see all the abo

How to Select li Element in Selenium Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using geckodriver because Selenium 3 enables geckodriver as the default WebDriver implementation for Firefox. Pre-requisites: geckodriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: it's a 4 steps process: Set webdriver.gecko.driver and its' path as a system property. Set the firefox diver and browse to the website. Get list items as Web elements using webdriver.findElements() function and CSS selector. Iterate over all these elements to get text and HTML. Let’s see all the above steps in the code. We will use Webelment.get

How to Get Link Text in Selenium Webdriver Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using geckodriver because Selenium 3 enables geckodriver as the default WebDriver implementation for Firefox. Pre-requisites: geckodriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: Getting link text takes 4 simple steps: Set webdriver.gecko.driver and its' path as a system property. Set the firefox diver and browse to the website. Get the HTML Div containing anchor tag as Web-element using webdriver.findElement() function and CSS selector. Get link text heading element and print. Let’s see all the above steps in the code. We wi

How to Get Selected Text From Dropdown in Selenium Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using geckodriver because Selenium 3 enables geckodriver as the default WebDriver implementation for Firefox. Pre-requisites: geckodriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: it's a 4 steps process: Set webdriver.gecko.driver and its' path as a system property. Set the firefox diver and browse to the website. Get all dropdown flex elements as Web elements using webdriver.findElements() function and css selector. Iterate over all these elements and get the data value of the one whose attribute aria-selected is true. Let’s s

How to Get Inner Text in Selenium Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using geckodriver because Selenium 3 enables geckodriver as the default WebDriver implementation for Firefox. Pre-requisites: geckodriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: Getting inner text takes 4 simple steps: Set webdriver.gecko.driver and its' path as a system property. Set the firefox diver and browse to the website. Get the HTML Div containing text as Web-element using webdriver.findElement() function and css selector. Find a text element and print its text. Let’s see all the above steps in the code. We will use

How to Click Submit Button in Selenium Webdriver Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using geckodriver  because Selenium 3 enables geckodriver as the default WebDriver implementation for Firefox. Pre-requisites: geckodriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: It's a 4 steps process: Set webdriver.gecko.driver and its' path as a system property. Set the firefox diver and browse to the website link. Get HTML Div containing submit button as a web element using webdriver.findElement() function and CSS selector. Find submit button using CSS selector and hit click. Let’s see all the above steps in the code. We will use

How to Get Response Status Code with Selenium Webdriver Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using geckodriver because Selenium 3 enables geckodriver as the default WebDriver implementation for Firefox. Pre-requisites: geckodriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: it's a 4 steps process: Set webdriver.gecko.driver and its' path as a system property. Set the firefox diver and browse to the website. Get URL from web driver  and try to open an HTTP connection using java.net.HttpURLConnection . Get response code using the built-in function. Let’s see all the above steps in the code. We will be using HttpURLConnection.getResponseCode() function to get the response s

How to Get Page Source in Selenium Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using geckodriver because Selenium 3 enables geckodriver as the default WebDriver implementation for Firefox. Pre-requisites: geckodriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: Getting page sources takes 3 simple steps: Set webdriver.gecko.driver and its' path as a system property. Set the firefox diver and browse to the website. Get the page source using built-in function of Webdriver. Let’s see all the above steps in the code. We will use Webelment.getPageSource() function to get source code of the browsed page. impo

How to Get href Value in Selenium Webdriver Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using geckodriver because Selenium 3 enables geckodriver as the default WebDriver implementation for Firefox. Pre-requisites: geckodriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: Getting href value takes 4 simple steps: Set webdriver.gecko.driver and its' path as a system property. Set the firefox diver and browse to the website. Get the HTML Div containing anchor tag as Web-element using webdriver.findElement() function and css selector. Get the href attribute and print. Let’s see all the above steps in the code. We will use We

How to Click href link in Selenium Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using geckodriver because Selenium 3 enables geckodriver as the default WebDriver implementation for Firefox. Pre-requisites: geckodriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: it's a  4 steps process: Set webdriver.gecko.driver and its' path as a system property. Set the firefox diver and browse to the website. Get the HTML Div anchor tag as Web-element using webdriver.findElement() function and css selector. Get the link and hit click. Let’s see all the above steps in the code. We will use Webelment.click() function to

How to Enter Username and Password in Selenium Webdriver Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using geckodriver  because Selenium 3 enables geckodriver as the default WebDriver implementation for Firefox. Pre-requisites: geckodriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: It's a 4 steps process: Set webdriver.gecko.driver and its' path as a system property. Set the firefox diver and browse to the website link. Get username and password web element;  input using webdriver.findElement() function and css selector. Send the values as keys. Let’s see all the above steps in the code. We will use webelement.sendKeys(CharSequence....KeystoSend) fu

How to Verify File Download in Selenium Webdriver Java

Image
Selenium is an open-source web-based automation tool that is implemented using a web driver.  We will be using geckodriver  because Selenium 3 enables geckodriver as the default WebDriver implementation for Firefox. Pre-requisites: geckodriver.exe maven dependency selenium <dependency> <groupid>org.seleniumhq.selenium</groupid> <artifactid>selenium-java</artifactid> <version>4.1.1</version> </dependency> Steps: The following 9 steps will automate the process: Set webdriver.gecko.driver and its' path as a system property. Set the firefox diver. Typecast web driver as Javascript executor.  Browse the website. Get the download button and click then wait to start downloading. Open the downloads section of the browser using the web driver. Get the file name of the