0
0
Selenium Javatesting~10 mins

Element screenshots in Selenium Java - Interactive Code Practice

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

Complete 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'
AsaveScreenshot
BtakeScreenshot
CcaptureScreenshot
DgetScreenshotAs
Attempts:
3 left
💡 Hint
Common Mistakes
Using takeScreenshot() which does not exist.
Using captureScreenshot() which is not a Selenium method.
2fill in blank
medium

Complete 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'
AOutputType
BScreenshotType
CFileType
DImageType
Attempts:
3 left
💡 Hint
Common Mistakes
Using ScreenshotType which is not a Selenium class.
Using FileType which does not exist in Selenium.
3fill in blank
hard

Fix 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'
AwriteFile
BcopyFile
CsaveFile
DmoveFile
Attempts:
3 left
💡 Hint
Common Mistakes
Using saveFile() which does not exist.
Using writeFile() which is not a FileUtils method.
4fill in blank
hard

Fill 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'
Aid
Bname
CFILE
DBASE64
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.
5fill in blank
hard

Fill 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'
AcssSelector
BFILE
CcopyFile
Dxpath
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.