Bird
0
0

Which of the following is the correct syntax to get the "href" attribute of a link element stored in variable link?

easy📝 Syntax Q3 of 15
Selenium Java - JavaScriptExecutor
Which of the following is the correct syntax to get the "href" attribute of a link element stored in variable link?
Alink.getValue("href");
Blink.getAttribute("href");
Clink.getProperty("href");
Dlink.getText("href");
Step-by-Step Solution
Solution:
  1. Step 1: Recall method to get attribute value

    The method to get an attribute value is getAttribute(String name).
  2. Step 2: Apply correct syntax to variable

    Calling link.getAttribute("href") correctly retrieves the href attribute.
  3. Final Answer:

    link.getAttribute("href"); -> Option B
  4. Quick Check:

    Correct syntax = getAttribute("href") [OK]
Quick Trick: Use getAttribute("attributeName") to get attribute value [OK]
Common Mistakes:
  • Using getText() to get attribute
  • Using getProperty() which is not standard in Selenium Java
  • Using getValue() which does not exist

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes