0
0
Selenium Pythontesting~10 mins

Submitting forms in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to submit the form using Selenium.

Selenium Python
submit_button = driver.find_element(By.ID, "submit")
submit_button.[1]()
Drag options to blanks, or click blank then click option'
Aget
Bsend_keys
Cclear
Dclick
Attempts:
3 left
💡 Hint
Common Mistakes
Using send_keys instead of click to submit the form.
Trying to use get() on a button element.
2fill in blank
medium

Complete the code to submit the form by calling the submit method on the form element.

Selenium Python
form = driver.find_element(By.TAG_NAME, "form")
form.[1]()
Drag options to blanks, or click blank then click option'
Asubmit
Bclick
Csend_keys
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using click() on the form element instead of submit().
Trying to send keys to the form element.
3fill in blank
hard

Fix the error in the code to submit the form by pressing Enter in the input field.

Selenium Python
input_field = driver.find_element(By.NAME, "username")
input_field.send_keys("user123" + [1])
Drag options to blanks, or click blank then click option'
AKeys.RETURN
BKeys.ENTER
CKeys.SUBMIT
DKeys.CLICK
Attempts:
3 left
💡 Hint
Common Mistakes
Using Keys.RETURN which may not work in all browsers.
Using Keys.SUBMIT or Keys.CLICK which do not exist.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps input names to their values for inputs with non-empty values.

Selenium Python
inputs = driver.find_elements(By.TAG_NAME, "input")
values = {input_element.get_attribute([1]): input_element.get_attribute([2]) for input_element in inputs if input_element.get_attribute('value') != ''}
Drag options to blanks, or click blank then click option'
A"name"
B"value"
C"id"
D"type"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' or 'type' instead of 'name' for keys.
Using 'name' for values instead of 'value'.
5fill in blank
hard

Fill all three blanks to create a test that asserts the form submission leads to the expected URL.

Selenium Python
submit_button = driver.find_element(By.CSS_SELECTOR, "button[type='submit']")
submit_button.[1]()
expected_url = "https://example.com/success"
actual_url = driver.[2]
assert actual_url [3] expected_url
Drag options to blanks, or click blank then click option'
Aclick
Bcurrent_url
C==
Dsubmit
Attempts:
3 left
💡 Hint
Common Mistakes
Using submit() on the button instead of click().
Using driver.url instead of driver.current_url.
Using != instead of == in the assertion.