Test your knowledge of essential Selenium commands, element locators, and basic test automation concepts using Python. This beginner-friendly quiz covers driver initialization, finding elements, test frameworks, file operations, browser navigation, frames, and more.
Which command should you use first in your Selenium script to open a browser using Python?
Explanation: The correct answer is 'from selenium import webdriver' because importing the webdriver module is the first step before creating a driver instance. 'driver.get()' is used after the driver is created, and 'find_element_by_id()' is for finding elements on a page. 'import driver.selenium' is not a valid import statement.
Which method helps you locate a single element on a page by its unique ID attribute in Selenium with Python?
Explanation: The correct answer is 'find_element_by_id', which locates an element using its unique ID. 'find_elements_by_tag' is used for locating elements by their tag name, and 'find_element_by_class' is incorrect since the actual method is 'find_element_by_class_name'. 'locate_element_id' is not a valid Selenium method.
When using pytest with Selenium, how should test function names be prefixed for automatic discovery?
Explanation: Pytest discovers test functions with names starting with 'test_'. Prefixes like 'sel_', 'auto_', or 'start_' won't be automatically detected by pytest as test cases. Using the 'test_' prefix ensures your functions are recognized as tests by the framework.
Before reading a CSV file in a Selenium script using Python, which module must you import?
Explanation: 'csv' is the correct module to import when working with CSV files. 'xlsx' and 'excel' do not exist as standard Python modules for CSV operations, and 'jsons' is related to JSON, not CSV data.
Which command is used to navigate the browser to a specific URL in Selenium with Python?
Explanation: 'driver.get()' is the correct command for navigating to a URL. 'driver.open_url()', 'driver.locate()', and 'driver.request()' are not standard Selenium methods for this operation. Only 'driver.get()' will open the desired webpage in the browser.
Which property gives you a list of all browser window handles currently open in Selenium?
Explanation: 'driver.window_handles' provides a list of all open window handles. The other options like 'driver.all_windows', 'driver.window_list', and 'driver.get_handles' do not exist in Selenium and would cause errors if used.
In Python's unittest framework, which method sets up resources once before any test methods in a class are run?
Explanation: 'setUpClass' is the correct method for setting up resources before any tests in the class run, and it should be decorated with @classmethod. 'startClass' and 'beginTest' are not valid unittest methods, while 'setUp' runs before each test method, not just once.
If you want to select an element using its CSS selector in Selenium, which method should you use?
Explanation: 'find_element_by_css_selector' is the correct Selenium method to select an element by CSS selector. 'find_css_element', 'locate_by_css', and 'select_element_by_css' are not valid method names in Selenium Python.
To upload a file with Selenium, what must you do after finding the relevant input element?
Explanation: You use 'send_keys' to send the file path to the file input element. Double clicking does not upload files, and there is no 'upload_file()' method in Selenium. Simply pressing Enter will not upload the file without specifying its path.
What Selenium method enables you to switch context into an iframe on a web page?
Explanation: 'driver.switch_to.frame' is the standard way in Selenium to switch into a specific frame. The options 'driver.go_to_frame', 'driver.enter_frame', and 'driver.set_frame' are not actual Selenium methods and would result in errors.
Which command allows you to navigate back to the previous page in the browser history using Selenium Python?
Explanation: 'driver.back()' directs the browser to go back. The commands 'driver.history()', 'driver.reverse()', and 'driver.previous()' are not defined in Selenium's API for navigating browser history.
Which Python library should be imported for reading Excel .xlsx files in Selenium test scripts?
Explanation: 'openpyxl' is the correct library for handling Excel .xlsx files in Python. 'csv' is for CSV files, 'json' is for JSON data, and 'xlxs' is a common typo for the correct term 'xlsx' but is not a library.
If you want to find a clickable hyperlink by its visible text in Selenium, which method should you use?
Explanation: 'find_element_by_link_text' focuses on locating anchor (link) elements by their displayed text. 'find_element_by_href' and 'find_element_by_text' are not Selenium methods. 'find_element_by_tagname' is for locating elements by tag, not link text.
What is the decorator used in pytest to create a fixture for resource setup or teardown?
Explanation: '@pytest.fixture' is the decorator for registering a function as a fixture in pytest. '@fixture', '@setup.fixture', and '@py.fixture' are invalid decorators and will not be recognized by pytest.
Which command refreshes the current browser page in Selenium with Python?
Explanation: 'driver.refresh()' reloads the current page in Selenium. 'driver.reload()', 'driver.update()', and 'driver.restart()' are not recognized Selenium commands for this operation and do not refresh the page.
When creating test classes in Python's unittest framework using Selenium, which class should your new test class inherit from?
Explanation: Test classes in unittest must inherit from 'unittest.TestCase' to work properly. 'unit.Testing', 'Test.UnitCase', and 'BaseTest' are incorrect and will not provide test discovery or assertion features.