Bird
Raised Fist0
Selenium Pythontesting~20 mins

Select by value, text, index in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Dropdown Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
What is the output of selecting option by value?

Given a dropdown with options having values '1', '2', '3', what will be the selected option text after selecting by value '2'?

Selenium Python
from selenium.webdriver.support.ui import Select

class DummySelect:
    def __init__(self):
        self.options = [{'value': '1', 'text': 'One'}, {'value': '2', 'text': 'Two'}, {'value': '3', 'text': 'Three'}]
        self.selected_option = None
    def select_by_value(self, value):
        for option in self.options:
            if option['value'] == value:
                self.selected_option = option['text']
                break
        else:
            self.selected_option = None

select = DummySelect()
select.select_by_value('2')
result = select.selected_option
A"1"
B"Two"
C"Three"
D"None"
Attempts:
2 left
💡 Hint

Remember, selecting by value matches the option's value attribute, not its text.

❓ query_result
intermediate
2:00remaining
What is the selected option text after selecting by visible text?

Given a dropdown with options 'Apple', 'Banana', 'Cherry', what will be the selected option value after selecting by visible text 'Banana'?

Selenium Python
from selenium.webdriver.support.ui import Select

class DummySelect:
    def __init__(self):
        self.options = [{'value': 'a', 'text': 'Apple'}, {'value': 'b', 'text': 'Banana'}, {'value': 'c', 'text': 'Cherry'}]
        self.selected_value = None
    def select_by_visible_text(self, text):
        for option in self.options:
            if option['text'] == text:
                self.selected_value = option['value']
                break
        else:
            self.selected_value = None

select = DummySelect()
select.select_by_visible_text('Banana')
result = select.selected_value
A"b"
B"None"
C"a"
D"Banana"
Attempts:
2 left
💡 Hint

Selecting by visible text matches the option's text, but the result asked is the value attribute.

❓ query_result
advanced
2:00remaining
What is the selected option text after selecting by index 1?

Given a dropdown with options ['Red', 'Green', 'Blue'], what is the selected option text after selecting by index 1?

Selenium Python
from selenium.webdriver.support.ui import Select

class DummySelect:
    def __init__(self):
        self.options = [{'value': 'r', 'text': 'Red'}, {'value': 'g', 'text': 'Green'}, {'value': 'b', 'text': 'Blue'}]
        self.selected_option = None
    def select_by_index(self, index):
        if 0 <= index < len(self.options):
            self.selected_option = self.options[index]['text']
        else:
            self.selected_option = None

select = DummySelect()
select.select_by_index(1)
result = select.selected_option
A"Green"
B"Red"
C"Blue"
D"None"
Attempts:
2 left
💡 Hint

Indexing starts at 0, so index 1 is the second option.

📝 Syntax
advanced
2:00remaining
Which option causes a SyntaxError when selecting by value?

Identify the code snippet that will cause a syntax error when trying to select an option by value.

Selenium Python
from selenium.webdriver.support.ui import Select

select = Select(driver.find_element_by_id('dropdown'))
Aselect.select_by_value('option1')
Bselect.select_by_value('option1'
Cselect.select_by_value('option1'))
Dselect.select_by_value(option1)
Attempts:
2 left
💡 Hint

Look for missing quotes or parentheses.

🔧 Debug
expert
3:00remaining
Why does selecting by index 5 cause an error?

Given a dropdown with 4 options, what error occurs when selecting by index 5 and why?

Selenium Python
from selenium.webdriver.support.ui import Select

class DummySelect:
    def __init__(self):
        self.options = [{'value': '1', 'text': 'One'}, {'value': '2', 'text': 'Two'}, {'value': '3', 'text': 'Three'}, {'value': '4', 'text': 'Four'}]
    def select_by_index(self, index):
        return self.options[index]['text']

select = DummySelect()
result = select.select_by_index(5)
AKeyError because 'text' key is missing
BNo error, returns 'Four'
CTypeError because options is not a list
DIndexError because index 5 is out of range
Attempts:
2 left
💡 Hint

Check the length of the options list and the index used.

Practice

(1/5)
1. Which method in Selenium Python is used to select an option from a dropdown by the visible text shown to the user?
easy
A. select_by_visible_text
B. select_by_value
C. select_by_index
D. select_option_by_text

Solution

  1. Step 1: Understand the method purpose

    select_by_visible_text selects dropdown options by the text users see.
  2. Step 2: Compare with other methods

    select_by_value uses the option's value attribute, select_by_index uses position, and select_option_by_text is not a valid method.
  3. Final Answer:

    select_by_visible_text -> Option A
  4. Quick Check:

    Select by visible text = select_by_visible_text [OK]
Hint: Visible text method name includes 'visible_text' [OK]
Common Mistakes:
  • Confusing select_by_value with select_by_visible_text
  • Using non-existent method names
  • Selecting by index when text is needed
2. Which of the following is the correct syntax to select an option by its value attribute using Selenium Python's Select class?
easy
A. select.select_by_index('option1')
B. select.select_by_value('option1')
C. select.select_by_text('option1')
D. select.select_value('option1')

Solution

  1. Step 1: Recall correct method name

    The method to select by value is select_by_value.
  2. Step 2: Check method usage

    It takes a string argument matching the option's value attribute, so select.select_by_value('option1') is correct.
  3. Final Answer:

    select.select_by_value('option1') -> Option B
  4. Quick Check:

    Select by value uses select_by_value() [OK]
Hint: Method name includes 'by_value' for value selection [OK]
Common Mistakes:
  • Using select_by_text instead of select_by_value
  • Passing index as string
  • Using non-existent methods like select_value
3. Given the following code snippet, what option will be selected?
from selenium.webdriver.support.ui import Select
select = Select(driver.find_element_by_id('dropdown'))
select.select_by_index(2)

Assuming the dropdown options are:
0: 'Apple'
1: 'Banana'
2: 'Cherry'
3: 'Date'
medium
A. 'Date'
B. 'Banana'
C. 'Cherry'
D. 'Apple'

Solution

  1. Step 1: Understand select_by_index

    The method selects the option at the given zero-based index.
  2. Step 2: Identify option at index 2

    Index 2 corresponds to 'Cherry' in the list.
  3. Final Answer:

    'Cherry' -> Option C
  4. Quick Check:

    Index 2 option = 'Cherry' [OK]
Hint: Index starts at 0, so 2 means third option [OK]
Common Mistakes:
  • Assuming index starts at 1
  • Confusing value with index
  • Selecting wrong option by off-by-one error
4. What is wrong with this Selenium Python code snippet?
select = Select(driver.find_element_by_id('dropdown'))
select.select_by_value(3)

Assuming the option values are strings like '1', '2', '3'.
medium
A. No error, code works fine
B. find_element_by_id is deprecated and causes error
C. select_by_value cannot select numeric values
D. select_by_value expects a string, not an integer

Solution

  1. Step 1: Check argument type for select_by_value

    This method requires a string matching the option's value attribute.
  2. Step 2: Identify type mismatch

    Passing integer 3 instead of string '3' causes a type mismatch and selection failure.
  3. Final Answer:

    select_by_value expects a string, not an integer -> Option D
  4. Quick Check:

    Value must be string for select_by_value() [OK]
Hint: Always pass string to select_by_value() [OK]
Common Mistakes:
  • Passing integer instead of string to select_by_value
  • Ignoring deprecation warnings (not main error here)
  • Assuming numeric values are auto-converted
5. You want to select the third option in a dropdown, but the options have duplicate visible texts and different values:
<option value='a'>Apple</option>
<option value='b'>Banana</option>
<option value='c'>Apple</option>
<option value='d'>Date</option>

Which method and argument will reliably select the second 'Apple' option?
hard
A. select.select_by_value('c')
B. select.select_by_visible_text('Apple')
C. select.select_by_index(1)
D. select.select_by_index(3)

Solution

  1. Step 1: Understand duplicate visible texts

    Using select_by_visible_text('Apple') selects the first 'Apple' option only.
  2. Step 2: Use unique value attribute

    The second 'Apple' has value 'c', so select_by_value('c') selects it reliably.
  3. Step 3: Index options

    Index 1 is 'Banana', index 2 is second 'Apple', but index can change if options reorder.
  4. Final Answer:

    select.select_by_value('c') -> Option A
  5. Quick Check:

    Use unique value to select duplicate text option [OK]
Hint: Use value attribute when visible text duplicates exist [OK]
Common Mistakes:
  • Selecting by visible text picks first duplicate only
  • Using wrong index due to zero-based counting
  • Assuming index is stable when options reorder
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