0
0
Selenium Javatesting~10 mins

Getting text and attributes in Selenium Java - 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 visible text of the web element.

Selenium Java
String text = element.[1]();
Drag options to blanks, or click blank then click option'
AgetAttribute
BgetText
CgetValue
DgetContent
Attempts:
3 left
💡 Hint
Common Mistakes
Using getAttribute instead of getText to get visible text.
Trying to use getValue which is not a WebElement method.
2fill in blank
medium

Complete the code to get the value of the 'href' attribute of the web element.

Selenium Java
String hrefValue = element.[1]("href");
Drag options to blanks, or click blank then click option'
AgetProperty
BgetValue
CgetText
DgetAttribute
Attempts:
3 left
💡 Hint
Common Mistakes
Using getText to get attribute values.
Using getValue which is not a WebElement method.
3fill in blank
hard

Fix the error in the code to correctly get the 'class' attribute of the element.

Selenium Java
String className = element.[1]("class");
Drag options to blanks, or click blank then click option'
AgetAttribute
BgetText
CgetClass
DgetProperty
Attempts:
3 left
💡 Hint
Common Mistakes
Using getClass which returns the Java class, not the attribute.
Using getText which returns visible text, not attribute.
4fill in blank
hard

Fill both blanks to get the text and the 'title' attribute of the element.

Selenium Java
String text = element.[1]();
String title = element.[2]("title");
Drag options to blanks, or click blank then click option'
AgetText
BgetValue
CgetAttribute
DgetContent
Attempts:
3 left
💡 Hint
Common Mistakes
Using getValue instead of getText for visible text.
Using getText to get attribute values.
5fill in blank
hard

Fill all three blanks to get the text, 'alt' attribute, and 'id' attribute of the element.

Selenium Java
String text = element.[1]();
String altText = element.[2]("alt");
String idValue = element.[3]("id");
Drag options to blanks, or click blank then click option'
AgetValue
BgetAttribute
CgetText
DgetProperty
Attempts:
3 left
💡 Hint
Common Mistakes
Using getValue which is not a WebElement method.
Using getText to get attribute values.