Embarking on a journey into automation testing with Selenium and Python? You're in the right place. In this beginner's guide, we'll demystify Selenium with Python, ensuring you grasp the fundamentals and build a solid foundation for your automation pursuits.

Before we dive in, ensure you have Python installed on your system. For Selenium, you'll need the WebDriver manager, which we'll install using pip. Now, let's get started!

Setting up Selenium with Python
```python !pip install selenium webdriver-manager ```

Understanding WebDriverManager
WebDriverManager automates the process of downloading and setting up the appropriate WebDriver executable. It ensures you're using the correct driver for your browser and operating system.

Here's how you'd initialize it in Python:
```python from selenium import webdriver from webdriver_manager.chrome import ChromeDriver driver = webdriver.Chrome(service=ChromeDriver().install()) ```
Initializing the WebDriver

Now that we've wrapped our heads around WebDriverManager, let's see how to initialize WebDriver for various browsers.
```python # For Chrome driver = webdriver.Chrome(service=ChromeDriver().install()) # For Firefox from selenium import webdriver from webdriver_manager.firefox import GeckoDriverManager driver = webdriver.Firefox(service=GeckoDriverManager().install()) # For Safari (macOS only) from selenium import webdriver from webdriver_manager.safari import SafariDriverManager driver = webdriver.Safari(service=SafariDriverManager().install()) ```
Navigating the Web with Selenium

Once you've initialized the WebDriver, you can start navigating and interacting with web elements. Let's explore some key methods.
```python driver.get("https://www.google.com") # Navigate to a URL driver.title # Get the title of the page driver.current_url # Get the current URL ```



















Finding Elements on the Page
Selenium uses different locator strategies to find elements on a web page. The most common ones are ID, name, class name, tag name, link text, partial link text, CSS selector, and XPath.
Here's how you'd find an element by ID:
```python from selenium.webdriver.common.by import By driver.find_element(By.ID, " Element ID ") ```
Interacting with Elements
After finding an element, you can interact with it. Here's how you'd send keys to a search input field:
```python search_input = driver.find_element(By.NAME, "q") search_input.send_keys("Selenium Python Tutorial") ```
Managing Window Handles
Sometimes, you might need to switch between windows or tabs. Selenium allows you to manage window handles easily.
```python driver.current_window_handle # Get the current handle driver.window_handles # Get all window handles driver.switch_to.window(window_name) # Switch to a window ```
Handling Alerts
Selenium can handle browser alerts with ease:
```python alert = driver.switch_to.alert alert.accept() # Accept the alert alert.dismiss() # Dismiss the alert ```
That's it! You've now learned the basics of Selenium with Python. Practice these concepts with practical examples to gain confidence. Happy automation testing!