Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to perform a right-click on the element.
Selenium Java
Actions actions = new Actions(driver);
actions.[1](element).perform(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using click() instead of contextClick() performs a left-click.
Using doubleClick() performs a double left-click, not right-click.
✗ Incorrect
The method contextClick() performs a right-click (context click) on the specified element.
2fill in blank
mediumComplete the code to build and perform the context click action.
Selenium Java
Actions actions = new Actions(driver);
actions.contextClick(element).[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using build() alone does not execute the action.
Using execute() or run() are not valid methods in Actions class.
✗ Incorrect
The perform() method executes the built action sequence immediately.
3fill in blank
hardFix the error in the code to correctly perform a right-click on the element.
Selenium Java
Actions actions = new Actions(driver);
actions.contextClick[1].perform(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting parentheses causes syntax errors.
Using brackets instead of parentheses is invalid syntax.
✗ Incorrect
The contextClick method requires parentheses with the element passed as an argument.
4fill in blank
hardFill both blanks to create an Actions object and perform a context click on the element.
Selenium Java
Actions [1] = new Actions([2]); [1].contextClick(element).perform();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'element' instead of 'driver' in the Actions constructor.
Using inconsistent variable names for the Actions object.
✗ Incorrect
We create an Actions object named 'actions' using the WebDriver 'driver'.
5fill in blank
hardFill all three blanks to right-click on an element located by id 'menu'.
Selenium Java
WebElement [1] = driver.findElement(By.[2]("menu")); Actions [3] = new Actions(driver); [3].contextClick([1]).perform();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.xpath instead of By.id for locating by id.
Using inconsistent variable names for Actions or WebElement.
✗ Incorrect
We find the element by id 'menu', store it in 'menuElement', create 'actions' object, then right-click.