Use a custom driver class instead of utility classes

How can I create my own driver class in Selenium? When learning test automation, you will want your test methods to be executed in multiple browsers such as Firefox and Chrome. A Firefox driver is created with the FirefoxDriver class: WebDriver driver = new FirefoxDriver(); A Chrome driver is created with the ChromeDriver class: WebDriver…

How to deal with windows authentication popups

  If you dont like Bugs Bunny, maybe you should not continue reading.   What is the first thing that I do every morning at work? Check the results of the automation scripts executed in Jenkins over night. I want to know how many scripts passed or failed because of the work done in the…

How to use locators with parameters

Sometimes, you need to interact in automation scripts with web elements that have similar HTML code. For example, you may want to automate the following test case: open site search for keyword check that the results page is displayed select the 2nd page of results check that the 2nd page is displayed select the 3rd…

Do not store element locators in property files

You have a small test automation project with about 50 test scripts and 10 page object classes. Each page object class uses approximately 10 web elements. The project has around 100 web element locators. Where should the elements’ locators be stored? Should they be stored in the page object classes, in enumerations, classes with static…

How to work with cookies

Browsers use cookies to store user preferences such as user location number of results per page sort order language Next time the user visits the site, the user preferences saved in the cookies are set automatically for the site. Each cookie is defined by the following fields: name value domain path expires size http isSecure…

How to create custom expected conditions in Selenium

You need custom expected conditions when the built-in Selenium WebDriver expected conditions are not sufficient for creating complex conditions. Short review of expected conditions Explicit waits and expected conditions are a great help for Selenium scripts. Selenium WebDriver comes with a lot of expected conditions such as ExpectedCondition < WebElement > elementToBeClickable(By locator) ExpectedCondition <…

How to handle random modal windows in Selenium

Many sites use modal windows for sales events, announcements and user surveys. Especially in the last 2 months of the year when there are so many holidays (Christmas, New Year’s Eve, Boxing Day). A modal is an HTML element that is displayed above the current page. It includes title description action button (take a survey,…

How to interact with sliders in Selenium WebDriver

Sliders allow users to select a value by dragging and dropping a handle. This value can be a price, a quantity, a year. The web page could use a textbox for getting the same information from users. But with sliders, the page becomes much more interesting. Actually, many web pages do not use the slider…

How to use regular expressions in Selenium WebDriver tests

  Regular expressions are a very useful technique for improving Selenium WebDriver tests. They can be used for extracting text from the value of a webelement validating if a value matches a specific pattern validating if a url matches a pattern Let’s look into regular expressions using a specific test case. Our test case does the…

How to execute JavaScript code in Selenium WebDriver

  WebDriver tests need to be executed in multiple browsers. And sometimes, you get different results. A button can be clicked correctly in Firefox but not in Chrome. What do you do in this case? Changing the locator may work. Executing JavaScript may work as well. Let’s investigate Javascript in this article. What can you…

Cannot click element? Execute JavaScript or use the Actions class

Have you ever seen this error in Chrome when trying to click on an element? org.openqa.selenium.WebDriverException: Element is not clickable at point (411, 675) Clicking the specific element works fine in Firefox but not at all in Chrome. The code is very straightforward: By locator = By.xpath(“//a[attribute=’value’]”); WebElement element = driver.findElement(locator); element.click(); So this does…