Selenium + Python · Lesson 5 of 43
Module 5: Functions
Try it yourself
Implement build_api_url(endpoint, base_url="https://targetqa.com", **params):
The editor has a worked example. Read it, tweak it, then press Mark as complete.
# Default arguments & type hints:
def wait_and_click(locator: str, timeout: int = 10, check_visible: bool = True):
print(f"Waiting up to {timeout}s for {locator}")
# Variable keyword arguments (**kwargs) for flexible parameters:
def create_test_user(username: str, **kwargs):
user = {"username": username, "role": kwargs.get("role", "STANDARD")}
return userFunctions encapsulate reusable actions and assertions. In this lesson, you will master default arguments, keyword arguments, variable-length *args and **kwargs for flexible locator helpers, and lambda functions. Let's design clean automation functions!
Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.
*args passes positional arguments as a tuple, while **kwargs passes arbitrary keyword arguments as a dictionary, perfect for flexible test configuration.
Finished reading?
Review the worked example in the editor, then mark the lesson complete.