Tag: selenium

Scroll Web Page

Level4, Selenium
We can scroll the web page using JavaScript Executor in the java code. I have taken the below examples with Five different scenarios of scrolling a webpage.  Scroll Down  Scroll up  Scroll bottom of the Page  Full scroll to bottom in slow motion automatically to your Web Element 1.Scroll Down: import java.util.concurrent.TimeUnit; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class PageScrollDown { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); //Launching the browser application driver.get("http://www.javaseleniumworld.com/"); //Adding wait driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); //Maxi

Selenium Introduction

Automation, Level1, Selenium, Uncategorised
Selenium Introduction: What is Automation Testing Benefits of Automation Testing When to automate an application: Steps to follow in Automation testing: Disadvantages of Automation Testing Different Automated Web Testing Tools Selenium Introduction Selenium Pros Selenium Cons Differences between selenium and other Tools What is Automation Testing? The Process of converting Manual Test cases into Test Script by using any automation tool is known as Automation Testing. Testers write test scripts and test cases using the automation tool and then group those test cases into test suites. Benefits of Automation Testing Reliable: Tests perform precisely the same operations each time they are run, thereby eliminating human error Repeatable: You can...

StaleElementReference Exception in Selenium

Selenium
StaleElementReference Exception occurs when driver is trying to perform action on the element which is no longer exists or not valid. What causes them? In short, a StaleElementException is calling a reference on an element that has been torn down.  There are many causes for them, here are some of the common ones I’ve seen. Page Refresh – I’ve seen this commonly working with tabbed pages.  Sometimes a page will look like 1 page with multiple tabs, but really are completely separate pages.  It might look like the same tab bar, but in reality you’ll have to re-find the element in order to work with it. JavaScript MVC frameworks – Many JavaScript MVC frameworks can update contents of a list or a control by rapidly tearing down and recreating the same element.  There are times an elem
CSS Selector

CSS Selector

Level3, Selenium
Locating elements by CSS Selectors There is a debate on the performance between CSS Locator and XPath locator and the debate on the performance of CSS and XPath locator is out of scope of this post. Most of the automation testers believe that using CSS selectors makes the execution of script faster compared to XPath locator. This locator is always the best way to locate elements on the page. Following are the some of the mainly used formats of CSS Selectors. Tag and ID Tag and Class Tag and Attribute Tag, Class and Attribute Sub-String Matches Starts With (^) Ends With ($) Contains (*) Child Elements Direct Child Sub-child nth child Matching By inner Text Tag and ID: Syntax: css=tag#id Open Mozilla Firefox and navigate to 

ElementNotVisible Exception

Selenium
Selenium ElementNotVisibleException is also one of the frequent exceptions which we will face in selenium webdriver while automating any kind of application. This exception tells you that the WebElement that you are trying to interact with is not visible to the user. If the element is not visible to the user then they are not going to able to interact with it   Below are the causes to face this exception: Thrown to indicate that although an element is present on the DOM, it is not visible, and so is not able to be interacted with. To overcome this kind of situation we need to use synchronization concept in selenium. So, add an explicit wait to wait for the correct conditions to be met before trying to interact with the element. We have an option to use wait in so many ways ...

NoSuchWindow Exception

Selenium
Selenium NoSuchWindowException is similar to NoSuchFrameException, this is also one of the frequent exceptions which we will face in selenium webdriver.   Sometimes applications will have child windows(i.e. Separate windows) which will open when you click on any link or button.   Normally if you want to automate the child windows then you need to switch to that window then only you can interact with the elements which are there on that window.   To overcome this, we need to handle the opened windows using one of the webdriver methods called “driver.getWindowHandles()”.   Once  you have this information then you can switch to the corresponding window to automate or interact with the window.     Below are the causes to face this ex
JavaScript Executor in Selenium

JavaScript Executor in Selenium

Level7, Selenium
As JavaScript Executor is an interface so we cannot create an object to this, for this we will type caste to driver object using below syntax:   JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript(javaScript, arguments); Now we will see some of the examples below that how we can use JavaScriptExecutor to execute the JavaScript to interact with the web elements.   1. How to enter value into textbox: JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("document.getElementById('email').value='[email protected]'");   2. How to click a button: JavascriptExecutor js = (JavascriptExecutor)driver; js.executeScript("document.querySelector('#enterimg').click()");   3. How to refresh a window: JavascriptExecutor js = (Javascri...
Basic Selenium Commands

Basic Selenium Commands

Level1, Selenium
Get Command get() command is use to open a new web page in the current browser. Command: driver.get(“URL”); Example : driver.get("http://google.com");   Get Title Command getTitle() command is use to get the title of the current page. Example : driver.getTitle();   Get Current URL Command getCurrentUrl() command is use to get the URL of the page currently loaded in the browser. Example : driver.getCurrentUrl()   Close Command close() command is use to close the current window of the browser, if it’s the last window it will close the browser. Example : driver.close();   Quit Command quit() command is use to quit the browser and all the opened windows in the browser. Example : driver.quit();   Get Page Source Command