Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to take a screenshot of a web element.
Selenium Java
WebElement element = driver.findElement(By.id("logo")); File screenshot = element.[1]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using takeScreenshot() which does not exist.
Using captureScreenshot() which is not a Selenium method.
✗ Incorrect
The method getScreenshotAs() is used to capture a screenshot of a web element in Selenium.
2fill in blank
mediumComplete the code to specify the output type for the screenshot.
Selenium Java
File screenshot = element.getScreenshotAs([1].FILE); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ScreenshotType which is not a Selenium class.
Using FileType which does not exist in Selenium.
✗ Incorrect
OutputType.FILE is used to specify that the screenshot should be saved as a file.
3fill in blank
hardFix the error in the code to save the element screenshot to a file.
Selenium Java
File screenshot = element.getScreenshotAs(OutputType.FILE); FileUtils.[1](screenshot, new File("element.png"));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using saveFile() which does not exist.
Using writeFile() which is not a FileUtils method.
✗ Incorrect
FileUtils.copyFile() copies the screenshot file to the desired location.
4fill in blank
hardFill both blanks to capture and save a screenshot of an element with id 'submit'.
Selenium Java
WebElement submitButton = driver.findElement(By.[1]("submit")); File screenshot = submitButton.getScreenshotAs(OutputType.[2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.name instead of By.id for locating by id.
Using OutputType.BASE64 which returns a string, not a file.
✗ Incorrect
By.id("submit") locates the element by id, and OutputType.FILE saves the screenshot as a file.
5fill in blank
hardFill all three blanks to capture an element screenshot and save it as 'button.png'.
Selenium Java
WebElement button = driver.findElement(By.[1]("button")); File screenshot = button.getScreenshotAs(OutputType.[2]); FileUtils.[3](screenshot, new File("button.png"));
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using cssSelector instead of xpath for locating.
Using OutputType.BASE64 instead of FILE.
Using FileUtils.moveFile instead of copyFile.
✗ Incorrect
By.xpath("button") locates the element by XPath, OutputType.FILE saves as file, and FileUtils.copyFile copies the file.