0
0
Selenium Pythontesting~10 mins

JavaScript executor basics 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 execute JavaScript that returns the page title.

Selenium Python
title = driver.execute_script([1])
Drag options to blanks, or click blank then click option'
A"return document.title"
B"document.title"
C"return title"
D"document.getTitle()"
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the return keyword causes the result to be None.
Using incorrect JavaScript syntax like document.getTitle() which does not exist.
2fill in blank
medium

Complete the code to scroll the page down by 500 pixels using JavaScript executor.

Selenium Python
driver.execute_script([1])
Drag options to blanks, or click blank then click option'
A"window.scroll(500, 0)"
B"scrollTo(0, 500)"
C"scrollBy(500, 0)"
D"window.scrollBy(0, 500)"
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping x and y values causes horizontal scrolling instead of vertical.
Using scrollTo without window. prefix may cause errors.
3fill in blank
hard

Fix the error in the code to click an element using JavaScript executor.

Selenium Python
driver.execute_script("arguments[0].[1]();", element)
Drag options to blanks, or click blank then click option'
AclickElement
Bclick
CclickOn
Dclicker
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent method names causes JavaScript errors.
Misspelling the method name leads to runtime failures.
4fill in blank
hard

Fill both blanks to return the inner text of an element using JavaScript executor.

Selenium Python
text = driver.execute_script("return arguments[[1]].[2]", element)
Drag options to blanks, or click blank then click option'
A0
B1
CinnerText
DtextContent
Attempts:
3 left
💡 Hint
Common Mistakes
Using argument index 1 causes undefined errors.
Using incorrect property names causes empty or undefined results.
5fill in blank
hard

Fill all three blanks to set the value of an input element using JavaScript executor.

Selenium Python
driver.execute_script("arguments[[1]].[2] = arguments[[3]]", input_element, value)
Drag options to blanks, or click blank then click option'
A0
B1
Cvalue
D"value"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up argument indexes causes errors or no effect.
Using string literal "value" instead of variable causes wrong assignment.