Bird
Raised Fist0
Selenium Pythontesting~20 mins

Find element by partial link text in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Partial Link Text Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ locator
intermediate
2:00remaining
Locate element using partial link text
You want to find a link on a webpage that contains the text "Learn" anywhere in its visible text. Which Selenium locator will correctly find this element?
Adriver.find_element(By.LINK_TEXT, "Learn")
Bdriver.find_element(By.PARTIAL_LINK_TEXT, "Learn")
Cdriver.find_element(By.PARTIAL_LINK_TEXT, "learn")
Ddriver.find_element(By.CSS_SELECTOR, "a[href*='Learn']")
Attempts:
2 left
💡 Hint
Partial link text matches part of the visible text, case sensitive.
❓ Predict Output
intermediate
2:00remaining
Output of partial link text locator code
Given the following HTML snippet:
<a href='/home'>Home Page</a>
<a href='/learn'>Learn Selenium</a>
<a href='/contact'>Contact Us</a>

What will be the text of the element found by:
element = driver.find_element(By.PARTIAL_LINK_TEXT, "Learn")
print(element.text)
ALearn Selenium
BContact Us
CHome Page
DNoSuchElementException
Attempts:
2 left
💡 Hint
Partial link text matches visible text containing the substring.
❓ assertion
advanced
2:00remaining
Assertion for partial link text element presence
You want to write a test assertion to verify that a link containing the text "Docs" is present on the page using Selenium in Python. Which assertion is correct?
Selenium Python
element = driver.find_element(By.PARTIAL_LINK_TEXT, "Docs")
Aassert element == None
Bassert element.text == "Docs"
Cassert element.is_displayed()
Dassert element.get_attribute('href') == "Docs"
Attempts:
2 left
💡 Hint
Check if the element is visible, not exact text or attribute.
🔧 Debug
advanced
2:00remaining
Debugging partial link text locator failure
You wrote this code to find a link containing "Help":
element = driver.find_element(By.PARTIAL_LINK_TEXT, "help")

But it raises NoSuchElementException even though the page has a link with text "Help Center". What is the most likely cause?
AThe element is inside an iframe and not accessible
BThe link text "Help Center" is too long for partial link text
CThe locator By.PARTIAL_LINK_TEXT does not work with spaces
DPartial link text matching is case sensitive, "help" does not match "Help"
Attempts:
2 left
💡 Hint
Check case sensitivity of partial link text.
❓ framework
expert
2:00remaining
Best practice for waiting for partial link text element
In a Selenium test, you want to wait up to 10 seconds for a link containing "Start" to appear before interacting with it. Which code snippet correctly implements this wait using WebDriverWait and partial link text locator?
Aelement = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, "Start")))
Belement = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "a:contains('Start')")))
Celement = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "start")))
Delement = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.LINK_TEXT, "Start")))
Attempts:
2 left
💡 Hint
Use correct locator and expected condition for presence.

Practice

(1/5)
1. What does the Selenium method find_element_by_partial_link_text do?
easy
A. Finds a link element containing the specified partial text.
B. Finds any element with the exact text match.
C. Finds elements by their HTML tag name.
D. Finds elements by their CSS class name.

Solution

  1. Step 1: Understand the method purpose

    The method find_element_by_partial_link_text searches for <a> elements that contain the given text partially.
  2. Step 2: Compare with other locator methods

    Unlike exact text match or tag name search, this method matches any link containing the partial text.
  3. Final Answer:

    Finds a link element containing the specified partial text. -> Option A
  4. Quick Check:

    Partial link text = Finds links with partial text [OK]
Hint: Partial link text finds links by part of their visible text [OK]
Common Mistakes:
  • Confusing partial link text with exact text match
  • Using it on non-link elements
  • Expecting it to find by attribute instead of visible text
2. Which of the following is the correct syntax to find a link containing the text "Login" using Selenium in Python?
easy
A. driver.find_element_by_partial_link_text['Login']
B. driver.find_element_by_partial_link_text(Login)
C. driver.find_element_by_partial_link_text("Login")
D. driver.find_element_by_partial_link_text{Login}

Solution

  1. Step 1: Check method usage and argument format

    The method requires a string argument inside parentheses and quotes, like "Login".
  2. Step 2: Validate Python syntax

    driver.find_element_by_partial_link_text("Login") uses correct parentheses and quotes. Options A, B, and D have syntax errors or wrong brackets.
  3. Final Answer:

    driver.find_element_by_partial_link_text("Login") -> Option C
  4. Quick Check:

    Correct method call uses parentheses and quotes [OK]
Hint: Use parentheses and quotes for string argument in method call [OK]
Common Mistakes:
  • Omitting quotes around the string
  • Using square or curly brackets instead of parentheses
  • Passing variable without quotes
3. What will the following code print if the page has a link with text "Click here to Login"?
element = driver.find_element_by_partial_link_text("Login")
print(element.text)
medium
A. NoSuchElementException
B. Login
C. Click here
D. Click here to Login

Solution

  1. Step 1: Understand partial link text matching

    The method finds the first link containing "Login" anywhere in its visible text.
  2. Step 2: Check what element.text returns

    It returns the full visible text of the found link, which is "Click here to Login".
  3. Final Answer:

    Click here to Login -> Option D
  4. Quick Check:

    Partial match finds full link text [OK]
Hint: Partial link text finds full link text, not just the partial part [OK]
Common Mistakes:
  • Expecting only the partial text to print
  • Assuming it throws exception if partial matches
  • Confusing element.text with attribute values
4. Given this code snippet, what is the error and how to fix it?
element = driver.find_element_by_partial_link_text(Login)
print(element.text)
medium
A. SyntaxError due to missing parentheses; fix by adding parentheses
B. NameError because Login is not quoted; fix by adding quotes: "Login"
C. NoSuchElementException because partial link text is incorrect
D. TypeError because find_element_by_partial_link_text expects int

Solution

  1. Step 1: Identify the error in argument usage

    The argument Login is not in quotes, so Python treats it as a variable, causing NameError.
  2. Step 2: Correct the argument to a string

    Wrap Login in quotes like "Login" to pass a string literal.
  3. Final Answer:

    NameError because Login is not quoted; fix by adding quotes: "Login" -> Option B
  4. Quick Check:

    String arguments need quotes [OK]
Hint: Always quote string arguments in Selenium locators [OK]
Common Mistakes:
  • Forgetting quotes around string literals
  • Assuming partial link text accepts variables without quotes
  • Misreading error type as syntax error
5. You want to click a link that contains either "Sign" or "Register" in its text. Which approach correctly finds and clicks the link using Selenium in Python?
hard
A. Try finding by partial link text "Sign" first, if not found, then try "Register".
B. Use find_element_by_partial_link_text("Sign or Register") to find either.
C. Use CSS selector to find links containing "Sign" or "Register" text.
D. Use find_element_by_link_text("Sign Register") to find combined text.

Solution

  1. Step 1: Understand partial link text limitation

    The method matches only one partial string at a time; it cannot match multiple alternatives in one call.
  2. Step 2: Implement fallback logic

    Try finding link with "Sign" first; if not found, catch exception and try "Register" next.
  3. Final Answer:

    Try finding by partial link text "Sign" first, if not found, then try "Register". -> Option A
  4. Quick Check:

    Partial link text matches one string; use fallback for multiple options [OK]
Hint: Try partial link texts one by one for multiple options [OK]
Common Mistakes:
  • Using 'or' inside partial link text string
  • Expecting one call to match multiple partial texts
  • Using link_text instead of partial_link_text for partial matches
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard