Table of Contents
Preface
Who should read this book
How to read this book
Recipe test scripts
Send me feedback
Introduction
Selenium language bindings: Java, C#, JavaScript, Python and Ruby
Cross-browser testing
RSpec
Run recipe scripts
Locating web elements
Start browser
Inspect Web Element in Browser
Find element by ID
Find element by Name
Find element by Link Text
Find element by Partial Link Text
Find element by XPath
Find element by Tag Name
Find element by Class
Find element by CSS Selector
Find element by Relative locators
Chain find_element to find child elements
Find multiple elements
Locate a Web Element that disappears after Inspect
Hyperlink
Click a link by text
Click a link by ID
Click a link by partial text
Click a link by XPath
Click Nth link with exact same label
Verify a link is present or not?
Getting link data attributes
Test links open a new browser window
Button
Click a button by text
Click a form button by text
Submit a form
Click a button by ID
Click a button by name
Click an image button
Click a button via JavaScript
Assert a button present
Assert a button enabled or disabled?
TextField and TextArea
Enter text into a text field by name
Enter text into a text field by ID
Enter text into a password field
Clear a text field
Enter text into a multi-line text area
Assert value
Focus on a control
Set a value to a read-only or disabled text field
Set and assert the value of a hidden field
Radio button
Select a radio button
Clear radio option selection
Assert a radio option is selected
Iterate radio buttons in a radio group
Click Nth radio button in a group
Click radio button by the following label
Customized Radio buttons - iCheck
CheckBox
Select by name
Uncheck a checkbox
Assert a checkbox is checked (or not)
Customized Checkboxes - iCheck
Select List
Select an option by text
Select an option by value
Select an option by index
Send keys to the select element
Select an option by iterating all options
Select multiple options
Clear one selection
Clear all selections
Assert a label or value in a select list
Assert selected option label
Assert the value of a select list
Assert multiple selections
Navigation and Browser
Go to a URL
Visit pages within a site
Perform actions from right mouse click context menu such as `Back', `Forward' or `Refresh'
Open browser in a certain size
Maximize browser window
Move browser window
Minimize browser window
Scroll focus to control vis JS
Scroll with Scroll Wheel Actions
Switch between browser windows or tabs
New Browser Window or Tab
Open new and close browser Tabs using JavaScript
Remember current web page URL, then come back to it later
Assertion
Assert page title
Assert Page Text
Assert Page Source
Assert Label Text
Assert Span text
Assert Div text or HTML
Assert Table text
Assert text in a table cell
Assert text in a table row
Assert image present
Assert element location and width
Assert element CSS style
Assert JS errors on a web page
Frames
Testing Frames
Find frames with find_element
Testing IFrame
Test multiple iframes
Testing AJAX
Wait within a time frame
Explicit Waits until Time out
Implicit Waits until Time out
Create your own polling check function
Wait AJAX Call to complete using JQuery
File Upload and Popup dialogs
File upload
JavaScript pop-ups
Modal style dialogs
Bypass basic authentication by embedding username and password in URL
Timeout on an operation
Internet Explorer modal dialog
Debugging Test Scripts
Print text for debugging
Write text to IDE output
Write page source or element HTML into a file
Take screenshots
Save the screenshot of a specific web element
Using IRB
Leave browser open after test finishes
Pause/Stop test execution at a certain step
Run selected test steps against current browser
Test Data
Get date dynamically
Get a random boolean value
Generate a number within a range
Get a random character
Get a random string at a fixed length
Get a random string in a collection
Generate random person names, emails, addresses with Faker
Generate a test file at fixed sizes
Retrieve data from Database
Browser Profile and Capabilities
Get browser type and version
Set HTTP Proxy for Browser
Verify file download in Chrome
Load Chrome extensions
Test downloading PDF in Firefox
Bypass basic authentication with Firefox AutoAuth plugin
Manage Cookies
Headless Chrome
Headless Firefox
Test responsive websites
Device emulation on Chrome
Set page load timeout
Testing slow pages that exceed default 60-second timeout
Advanced User Interactions
Double click a control
Move the mouse to a control - Mouse Over
Click and hold - select multiple items
Context Click - right click a control
Drag and drop
Drag slider
Send key sequences - Select All and Delete
Click a specific part of an image
Mouse move to coordinates
HTML 5 and JavaScript
HTML5 Email type field
HTML5 Time Field
Invoke `onclick' JavaScript event
Invoke JavaScript events such as `onchange'
Scroll to the bottom of a page
Select2 - Single Select
Select2 - Multiple Select
AngularJS web pages
Ember JS web pages
``Share Location'' with Firefox
Faking Geolocation with JavaScript
Save a canvas to PNG image
Verify dynamic charts
TinyMCE
CKEditor
SummerNote
CodeMirror
Leverage Programming
Raise exceptions to fail a test
Ignorable test statement error
Read external file
Data-Driven Tests with Excel
Data-Driven Tests with CSV
Identify element IDs with dynamically generated long prefixes
Sending special keys to an element or browser
Use of Unicode in test scripts
Extract a group of dynamic data : verify search results in order
Verify the uniqueness of a set of data
Extract dynamic visible data rows from a table
Extract dynamic text following a pattern using Regex
Quick extract pattern text in comments with Regex
Optimization
Assert text in page_source is faster than the text
Getting the text from a more specific element is faster
Avoid programming if-else block code if possible
Use variable to cache not-changed data
Enter large text into a text box
Use Environment Variables to change test behaviors dynamically
Test website in two languages
Multi-language testing with lookups
Gotchas
Test starts browser but no execution with a blank screen
Failed to assert copied text in the browser
The same test works for Chrome, but not IE
``unexpected tag name `input'''
Element is not clickable or not visible
Lack of knowledge of the programming language
Extend Selenium
Watir
RWebSpec
Capybara
Selenium with Cucumber
How Selenium-WebDriver is integrated with Cucumber?
Execute Cucumber tests
Cucumber or RSpec?
Material Design Web App
Select List (dropdown)
Checkbox
Drag range (noUiSlider)
Verify Toast message
Modal
Selenium Grid
Selenium Server Standalone
Execute tests on a remote machine
Set up Selenium Grid
Using Selenium Grid to run tests
Issues with Selenium Grid
Selenium 4
New Browser Window or Tab
Basic Authentication via register
Print to PDF
Save element screenshot
Relative Locators
Scroll Wheel Actions
Selenium DevTools
General
Event
Network
Emulate
Page
Quiz
Answers
Afterword
Resources
Books
websites
Blog
Tools
This book is for testers or programmers who write (or want to learn) automated tests with Selenium WebDriver. In order to get the most of this book, basic Ruby coding skill is required.Usually, a ‘recipe’ book is a reference book. Readers can go directly to the part that interests them. For example, if you are testing a multiple select list and don’t know how, you can look up in the Table of Contents, then go to chapter 8. This book supports this style of reading.If you are new to Selenium WebDriver, I recommend you to try out the recipes from the front to back. The recipes in the first half of the book are arranged according to their levels of complexity, I believe readers can get the pattern of testing with Selenium and gain confidence after going through them