0
0
Selenium Javatesting~10 mins

findElement by linkText 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 find a link by its exact visible text.

Selenium Java
WebElement link = driver.findElement(By.[1]("Home"));
Drag options to blanks, or click blank then click option'
ApartialLinkText
Bid
CcssSelector
DlinkText
Attempts:
3 left
💡 Hint
Common Mistakes
Using partialLinkText instead of linkText will find links by partial text, not exact.
Using cssSelector or id won't work for finding links by visible text.
2fill in blank
medium

Complete the code to click a link with the exact text "Contact Us".

Selenium Java
driver.findElement(By.[1]("Contact Us")).click();
Drag options to blanks, or click blank then click option'
AlinkText
Bid
Cname
DclassName
Attempts:
3 left
💡 Hint
Common Mistakes
Using id, name, or className won't find links by visible text.
Using partialLinkText would work but is not exact match.
3fill in blank
hard

Fix the error in the code to find a link with text "About".

Selenium Java
WebElement aboutLink = driver.findElement(By.[1]("About"));
Drag options to blanks, or click blank then click option'
AlinkText
BpartialLinkText
Cxpath
DtagName
Attempts:
3 left
💡 Hint
Common Mistakes
Using partialLinkText when exact match is required.
Using xpath or tagName won't find by visible link text directly.
4fill in blank
hard

Fill both blanks to find and click a link with text "Services".

Selenium Java
WebElement serviceLink = driver.findElement(By.[1]("Services"));
serviceLink.[2]();
Drag options to blanks, or click blank then click option'
AlinkText
Bclick
Csubmit
DpartialLinkText
Attempts:
3 left
💡 Hint
Common Mistakes
Using partialLinkText instead of linkText for exact match.
Using submit() instead of click() to click a link.
5fill in blank
hard

Fill all three blanks to find a link with text "Login", check if it is displayed, and then click it.

Selenium Java
WebElement loginLink = driver.findElement(By.[1]("Login"));
if (loginLink.[2]()) {
    loginLink.[3]();
}
Drag options to blanks, or click blank then click option'
AlinkText
BisDisplayed
Cclick
DisEnabled
Attempts:
3 left
💡 Hint
Common Mistakes
Using partialLinkText instead of linkText.
Using isEnabled() instead of isDisplayed() to check visibility.
Forgetting to check visibility before clicking.