0
0
Selenium Pythontesting~10 mins

Why element location is the core skill in Selenium Python - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to find a button by its ID using Selenium.

Selenium Python
button = driver.find_element_by_[1]('submit-btn')
Drag options to blanks, or click blank then click option'
Atag_name
Bid
Cname
Dclass_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' when the element has an ID attribute.
Confusing 'class_name' with 'id'.
2fill in blank
medium

Complete the code to locate an element using XPath in Selenium.

Selenium Python
element = driver.find_element_by_[1]('//div[@class="content"]')
Drag options to blanks, or click blank then click option'
Aid
Bcss_selector
Cxpath
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'css_selector' when the locator is an XPath expression.
Trying to use 'id' with an XPath string.
3fill in blank
hard

Fix the error in the code to correctly locate an element by CSS selector.

Selenium Python
element = driver.find_element_by_[1]('.main-content > p')
Drag options to blanks, or click blank then click option'
Acss_selector
Bxpath
Cid
Dclass_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'xpath' with a CSS selector string.
Using 'id' or 'class_name' incorrectly with complex selectors.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps element texts to their IDs for elements with class 'item'.

Selenium Python
elements = driver.find_elements_by_class_name('item')
text_id_map = [1]: el.get_attribute('id') for el in elements if el.text [2] ''
Drag options to blanks, or click blank then click option'
A{el.text
B==
C!=
D[el.text
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets instead of curly braces for dictionary comprehension.
Using '==' instead of '!=' to filter out empty texts.
5fill in blank
hard

Fill all three blanks to create a test assertion that checks if the page title contains the word 'Dashboard'.

Selenium Python
title = driver.title
assert [1] in [2], 'Title does not contain [3]'
Drag options to blanks, or click blank then click option'
A'Dashboard'
Btitle
Ddriver.title
Attempts:
3 left
💡 Hint
Common Mistakes
Using driver.title directly instead of the variable.
Mixing up the order of substring and string in the 'in' expression.