Install Selenium WebDriver:
gem install selenium-webdriver
A concise guide to using Selenium WebDriver with Ruby for automated web testing. Covers setup, basic commands, element interaction, waits, and best practices.
Install Selenium WebDriver:
|
Basic Project Setup:
|
Require Statement:
|
Driver Configuration (ChromeDriver): |
Initialize Driver:
|
Alternative Driver Initialization (with options):
|
Launch and Navigate: |
|
Get Current URL: |
|
Get Page Title: |
|
Refresh Page: |
|
Navigate Back/Forward: |
|
Quit/Close Browser: |
|
Finding a Single Element: |
By ID:
|
By Name:
|
By Class Name:
|
By CSS Selector:
|
By XPath:
|
Finding Multiple Elements: |
Example:
|
Clicking: |
|
Sending Keys (Typing): |
|
Clearing Text Field: |
|
Getting Text: |
|
Getting Attribute Value: |
|
Is Element Displayed?: |
|
Is Element Enabled?: |
|
Is Element Selected?: |
|
Implicit Wait: |
Example:
|
Explicit Wait: |
Example:
|
Expected Conditions (with explicit wait):
|
Sleep (Avoid if possible): |
Example:
|
Switching to Alert: |
|
Accepting Alert: |
|
Dismissing Alert: |
|
Getting Alert Text: |
|
Switching to IFrame (by index): |
|
Switching to IFrame (by name or ID): |
|
Switching back to Default Content: |
|
Action Chains (Mouse Actions): |
Example (Hover):
|
Example (Drag and Drop):
|
Example (Right Click):
|
Taking Screenshot: |
|
Saving HTML Source: |
|
Debugging Tips: |
|
Page Object Model (POM): |
Example:
|