Challenge - 5 Problems
Action Method Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of action method performing click
What will be the output of the following Selenium Python code snippet when the
click_login method is called?Selenium Python
from selenium.webdriver.common.by import By class LoginPage: def __init__(self, driver): self.driver = driver self.login_button = (By.ID, 'loginBtn') def click_login(self): element = self.driver.find_element(*self.login_button) element.click() return 'Clicked' # Assume driver is a valid WebDriver instance and login button is present.
Attempts:
2 left
💡 Hint
Look at what the method returns after clicking the element.
✗ Incorrect
The method finds the element and clicks it, then returns the string 'Clicked'. So the output is 'Clicked'.
❓ assertion
intermediate2:00remaining
Correct assertion for verifying text after action
Given a page class with a method
get_welcome_message that returns the welcome text after login, which assertion correctly verifies the message is 'Welcome User'?Selenium Python
from selenium.webdriver.common.by import By class HomePage: def __init__(self, driver): self.driver = driver def get_welcome_message(self): return self.driver.find_element(By.ID, 'welcomeMsg').text # After login, test calls home_page.get_welcome_message()
Attempts:
2 left
💡 Hint
Check for exact equality of the returned text.
✗ Incorrect
Option C asserts the returned text exactly matches 'Welcome User', which is the correct way to verify the message.
❓ locator
advanced2:00remaining
Best locator strategy for action method
Which locator is the best choice for an action method that clicks a submit button with a unique class name 'submit-btn'?
Attempts:
2 left
💡 Hint
Consider specificity and reliability of locators.
✗ Incorrect
Using CSS_SELECTOR with 'button.submit-btn' is specific and reliable for a button with that class. CLASS_NAME may fail if multiple classes exist. ID is invalid if not present.
🔧 Debug
advanced2:00remaining
Identify error in action method
What error will occur when running this action method that tries to send keys to a text field?
Selenium Python
from selenium.webdriver.common.by import By class SearchPage: def __init__(self, driver): self.driver = driver self.search_input = (By.ID, 'searchBox') def enter_search_term(self, term): element = self.driver.find_element(*self.search_input) element.send_keys(term)
Attempts:
2 left
💡 Hint
Check how find_element is called with locator tuple.
✗ Incorrect
The method calls find_element with a single tuple argument instead of unpacking it with *; this causes a TypeError.
❓ framework
expert3:00remaining
Design pattern for reusable action methods
In a Selenium test framework using page classes, which design approach best supports reusable action methods for different pages?
Attempts:
2 left
💡 Hint
Think about code reuse and maintainability.
✗ Incorrect
A BasePage class with common actions inherited by all pages promotes reuse and cleaner code.