5 important Tricks/Methods in selenium automation

Test Automation

In test automation using selenium, there are a couple of methods which are effective and useful.

Some of these important tricks/Methods are mentioned below.

1- getPagesource-Reading page source of a web page, using getpagesource method, which brings full page source, it brings same page source value which brings on right clicking mouse for seeing page source manually.

It is possible that a test developer requires some page text which does not have a specific locator.

How to do it-

String str ;
str = driver.getPageSource

now using str in conditional statement test automation developer can perform a various action.

2- Switching to a web frame-(frame with random id) using custom sync handling

usually switch to frame can be done by below syntax-

a- to a specific index- driver.switchTo().frame(0);
b- to a specific locator- driver.switchTo().frame("id of the element");
c- if no of frames are known but locator id is not static, then switching to that frame can be done using below piece of code-

int i=0
Int size = driver.findElements(By.tagName("iframe")).size();

3- Refreshing of a web page

An already opened webpage can be refreshed by using driver.navigate.refresh()

4- Using try-catch statement as if/else-

It happens sometimes that a particular webobject has 2 different values and there is no nested condition available to incorporate for e.g. a child hyperlink inside a tree which has 2 properties. which can be handled as
catch(exception ex)

5- Use of JavaScriptExecutor– Use of javascriptexecutor for interacting with webelement.

WebElement button = driver.findelement("Xpath");
JavascriptExecutor js = (JavascriptExecutor)driver;
//Perform Click on LOGIN button using JavascriptExecutor
js.executeScript("arguments[0].click();", button);

There are multiple ways to fix any issue or to create script however it depends on the situation when to use what. Above mentioned tricks can be helpful in many cases.

Its Prashant Chaudhary, I have 10+ years of experience in software test automation, performance & process automation with various commercial and open source tools. This blog shares my experience on the topic of Automation. The content published on my blog is solely mine, it does not express the views of any of my employers (current or previous).

I have experienced in automation framework designing, planning, doing maturity assessment of automation (F/W, scripts) and automation tool evaluation. Good understanding in various kinds of automation- that includes Application, and Process Automation. Implemented various CI tools, Used VSO, Jenkins, and Bamboo for implementing Test automation in CI/CD and robotic process automation using open source solution(Selenium). Skilled in leading automation team, managing vendors in automation & functional QA projects.

Tool Knowledge-
Selenium WebDriver, IBM RFT, HP UFT, Appium, Sahi Pro, Sikuli
Mobile Automation- Appium, Perfecto, Nokia Automation Tools- Auster, Phoenix, Trap
Performance Testing tool- IBM RPT, JMeter, Empirix, Neoload HttpWatch.
CI Tools- VSO, Jenkins and Bamboo

I Completed my B.Tech in computer science from UPTU University – Lucknow in the year 2007.

I like to write on selenium/Automation in my spare time . I started writing this blog 2 year ago and now my blog has grown upto 1000+Subscribers.

Drop me an email if you have any query or any help is required in Automation.

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Test Automation
What is ITestListner interface and its Use in Selenium

There are several interfaces available in TestNG that allow you to modify TestNG’s behavior or to give test scripts additional strength. These interfaces are broadly called “TestNG Listeners”. Here are a few listeners which are commonly used: 1- IAnnotationTransformer 2- IAnnotationTransformer2 3- IHookable 4- IInvokedMethodListener 5- IMethodInterceptor 6- IReporter 7- …

Test Automation
How to Capture Screenshot in Selenium Webdriver-3 different ways

Abstract– Capturing screenshot is an essential feature of a test automation framework, They help in defect analyses once after test execution is over. In this blog post we will see how to capture screenshot, there are different ways to capture screenshots. Which includes- 1- Capture full Page 2- Capturng full …

Test Automation
What is Headless browser automation

Hello Readers, In this post we will read about headless browser automation and how to use or invoke different headless browser using selenium. First of all lets understand What is a headless browser? A headless browser is a web-browser without a GUI-Graphical User Interface. The major difference with browser having …