Bird
0
0

Given this code snippet, what will be printed?

medium📝 Predict Output Q5 of 15
Selenium Python - Advanced Patterns
Given this code snippet, what will be printed?
from selenium.webdriver.common.by import By
button = driver.find_element(By.CSS_SELECTOR, 'button.submit')
print(button.text)

Assuming the button has the text 'Send'.
Abutton.submit
BCSS Selector
CSend
DNo output, raises NoSuchElementException
Step-by-Step Solution
Solution:
  1. Step 1: Understand find_element with CSS selector

    The code finds the first button element with class 'submit'.
  2. Step 2: Check the print statement

    button.text returns the visible text inside the button, which is 'Send'.
  3. Final Answer:

    Send -> Option C
  4. Quick Check:

    find_element + .text = element text [OK]
Quick Trick: Use .text to get visible element text [OK]
Common Mistakes:
  • Printing the selector string instead of text
  • Confusing attribute with text property
  • Assuming element not found without reason

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes