0
0
Selenium Pythontesting~10 mins

Find element by tag name 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 the first <button> element on the page.

Selenium Python
button = driver.find_element(By.[1], "button")
Drag options to blanks, or click blank then click option'
ANAME
BID
CCLASS_NAME
DTAG_NAME
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.ID or By.CLASS_NAME instead of By.TAG_NAME.
Forgetting to import By from selenium.webdriver.common.by.
2fill in blank
medium

Complete the code to find all <div> elements on the page.

Selenium Python
divs = driver.find_elements(By.[1], "div")
Drag options to blanks, or click blank then click option'
ATAG_NAME
BNAME
CCLASS_NAME
DCSS_SELECTOR
Attempts:
3 left
💡 Hint
Common Mistakes
Using find_element instead of find_elements to get multiple elements.
Using wrong locator type like CLASS_NAME for tag name search.
3fill in blank
hard

Fix the error in the code to find the <h1> element by tag name.

Selenium Python
header = driver.find_element(By.[1], "h1")
Drag options to blanks, or click blank then click option'
ATAG_NAME
BCLASS_NAME
CID
DNAME
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.CLASS_NAME or By.ID when searching by tag name.
Typos in the locator string.
4fill in blank
hard

Fill both blanks to find all <li> elements and get the text of the first one.

Selenium Python
items = driver.find_elements(By.[1], "li")
first_text = items[[2]].text
Drag options to blanks, or click blank then click option'
ATAG_NAME
B0
C1
DCLASS_NAME
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 1 instead of 0 to get the first element.
Using wrong locator like CLASS_NAME for tag name search.
5fill in blank
hard

Fill all three blanks to find the first <a> element, get its href attribute, and check it contains 'http'.

Selenium Python
link = driver.find_element(By.[1], "a")
href = link.get_attribute([2])
assert [3] in href
Drag options to blanks, or click blank then click option'
ATAG_NAME
B"href"
C"http"
D"src"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'src' instead of 'href' for link attribute.
Checking for 'src' or wrong substring in href.
Using wrong locator instead of TAG_NAME.