0
0
Selenium Pythontesting~10 mins

Getting element text 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 get the text of the element with id 'message'.

Selenium Python
element = driver.find_element(By.ID, 'message')
text = element.[1]
Drag options to blanks, or click blank then click option'
Aget_text()
Btext
CinnerText
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using get_text() which is not a Selenium WebElement method.
Trying to access 'value' which is for input elements' values.
2fill in blank
medium

Complete the code to get the text of the first <p> element on the page.

Selenium Python
element = driver.find_element(By.TAG_NAME, 'p')
text = element.[1]
Drag options to blanks, or click blank then click option'
AinnerHTML
BgetText()
Ctext
Dcontent
Attempts:
3 left
💡 Hint
Common Mistakes
Using innerHTML which returns HTML content, not just text.
Trying to call getText() which is not a Python Selenium method.
3fill in blank
hard

Fix the error in the code to correctly get the text of the element with class 'title'.

Selenium Python
element = driver.find_element(By.CLASS_NAME, 'title')
text = element.[1]()
Drag options to blanks, or click blank then click option'
Atext
Bget_text
CgetText
DinnerText
Attempts:
3 left
💡 Hint
Common Mistakes
Calling element.text() as if it were a method.
Using JavaScript style properties like innerText directly.
4fill in blank
hard

Fill both blanks to get the text of the element with id 'header' and check if it equals 'Welcome'.

Selenium Python
element = driver.find_element(By.[1], 'header')
assert element.[2] == 'Welcome'
Drag options to blanks, or click blank then click option'
AID
Btext
Cclass_name
Dget_text
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class_name' instead of 'ID' for locating by id.
Trying to call get_text() which is not a Selenium method.
5fill in blank
hard

Fill all three blanks to get the text of the element with CSS selector '.nav-item.active' and verify it contains 'Home'.

Selenium Python
element = driver.find_element(By.[1], '.nav-item.active')
text = element.[2]
assert 'Home' [3] text
Drag options to blanks, or click blank then click option'
ACSS_SELECTOR
Btext
Cin
Dcontains
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contains' which is not a Python operator.
Trying to call get_text() instead of using the text property.