0
0
Selenium Javatesting~5 mins

Getting text and attributes in Selenium Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What method in Selenium Java is used to get the visible text of a web element?
The getText() method is used to retrieve the visible text of a web element.
Click to reveal answer
beginner
How do you get the value of an attribute from a web element in Selenium Java?
Use the getAttribute(String attributeName) method, passing the attribute name as a string.
Click to reveal answer
intermediate
What will element.getText() return if the element is hidden on the page?
It will return an empty string because getText() only returns visible text.
Click to reveal answer
intermediate
Why might getAttribute("value") be preferred over getText() for input fields?
Because input fields often store their content in the "value" attribute, not as visible text, so getAttribute("value") retrieves the entered text.
Click to reveal answer
beginner
What is the difference between getText() and getAttribute() in Selenium?
getText() returns the visible text inside an element. getAttribute() returns the value of a specified attribute of the element, which may not be visible text.
Click to reveal answer
Which Selenium Java method retrieves the visible text of a web element?
AgetContent()
BgetAttribute()
CgetText()
DgetValue()
How do you get the 'href' attribute of a link element in Selenium Java?
Aelement.getLink()
Belement.getText()
Celement.getValue("href")
Delement.getAttribute("href")
What does element.getText() return if the element is not visible?
AThe text inside the element
BEmpty string
Cnull
DThrows an exception
Which method is best to get the typed text inside an input field?
AgetAttribute("value")
BgetText()
CgetInput()
DgetContent()
What is the return type of getAttribute() in Selenium Java?
AString
Bint
Cboolean
Dvoid
Explain how to retrieve visible text and attribute values from web elements using Selenium Java.
Think about what you see on the page versus what is stored in element attributes.
You got /4 concepts.
    Describe a scenario where getText() might not return the expected text and how to handle it.
    Consider input fields and hidden elements.
    You got /4 concepts.