When using Selenium for automated testing, certain parameters are required to ensure test scripts execute properly. These parameters are typically related to initiating and controlling browser sessions. The four required parameters are as follows:
-
Driver Executable Path: This specifies the path to the driver executable, such as ChromeDriver or GeckoDriver, which is required because Selenium uses it to control the corresponding browser. For example, when automating tests with Chrome, the path to ChromeDriver must be specified.
Example code:
pythonfrom selenium import webdriver # Set the ChromeDriver path driver = webdriver.Chrome(executable_path='path/to/chromedriver') -
Browser Name: The browser name must be specified, such as Chrome or Firefox, typically when using Remote WebDriver.
Example code:
pythonfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilities # Create a DesiredCapabilities object specifying the browser name capabilities = DesiredCapabilities.CHROME.copy() driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=capabilities) -
Test URL: The test URL is required as it defines the starting point for automation.
Example code:
pythondriver.get('http://www.example.com') -
Implicit Wait/Explicit Wait: Waiting for elements to be visible or interactable is common in automated testing. Selenium provides implicit and explicit waits to handle element loading times. While not startup parameters, they are essential settings in the script to prevent test failures due to incomplete page loading.
Example code:
python# Set implicit wait driver.implicitly_wait(10) # in seconds # Explicit wait from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC element = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, "myElement")) )
These parameters are essential settings to ensure Selenium automation scripts execute smoothly.