0
0
Selenium Pythontesting~10 mins

XPath with attributes in Selenium Python - Interactive Code Practice

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

Complete the code to find a button with the attribute id='submit'.

Selenium Python
button = driver.find_element(By.XPATH, "//button[@[1]='submit']")
Drag options to blanks, or click blank then click option'
Aid
Bclass
Cname
Dtype
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'id' when the button's id attribute is needed.
Using 'name' or 'type' which may not uniquely identify the button.
2fill in blank
medium

Complete the code to find an input element with attribute type='checkbox'.

Selenium Python
checkbox = driver.find_element(By.XPATH, "//input[@[1]='checkbox']")
Drag options to blanks, or click blank then click option'
Aname
Btype
Cid
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' or 'id' which do not specify the input type.
Confusing 'name' with 'type' attribute.
3fill in blank
hard

Fix the error in the XPath to find a link with attribute href='#home'.

Selenium Python
link = driver.find_element(By.XPATH, "//a[@[1]='#home']")
Drag options to blanks, or click blank then click option'
Aalt
Bsrc
Chref
Dtitle
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'src' which is for images, not links.
Using 'alt' or 'title' which are not link targets.
4fill in blank
hard

Fill both blanks to find a div with class='container' and data-role='main'.

Selenium Python
element = driver.find_element(By.XPATH, "//div[@[1]='container' and @[2]='main']")
Drag options to blanks, or click blank then click option'
Aclass
Bid
Cdata-role
Drole
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' instead of 'class' for the first attribute.
Using 'role' instead of 'data-role' for the second attribute.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps input names to their placeholder text if the input is required.

Selenium Python
placeholders = [1]: [2] for [3] in inputs if [3].get_attribute('required') is not None}
Drag options to blanks, or click blank then click option'
Ainput.get_attribute('name')
Binput.get_attribute('placeholder')
Cinput
Delement
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'element' instead of 'input' as the loop variable.
Mixing up keys and values in the dictionary comprehension.