0
0
Selenium Javatesting~10 mins

Element dimensions and location 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 get the width of a web element.

Selenium Java
int width = element.getSize().[1]();
Drag options to blanks, or click blank then click option'
AgetLocation
BgetWidth
CgetHeight
DgetDimension
Attempts:
3 left
💡 Hint
Common Mistakes
Using getHeight() instead of getWidth()
Using getLocation() which returns position, not size
2fill in blank
medium

Complete the code to get the Y coordinate of a web element's location.

Selenium Java
int yPosition = element.getLocation().[1]();
Drag options to blanks, or click blank then click option'
AgetY
BgetX
CgetWidth
DgetHeight
Attempts:
3 left
💡 Hint
Common Mistakes
Using getX() which returns horizontal position
Using getWidth() which returns size, not position
3fill in blank
hard

Fix the error in the code to get the element's height.

Selenium Java
int height = element.getSize().[1]();
Drag options to blanks, or click blank then click option'
AgetHeight
BgetWidth
CgetLocation
DgetPosition
Attempts:
3 left
💡 Hint
Common Mistakes
Using getWidth() instead of getHeight()
Using getLocation() which returns position, not size
4fill in blank
hard

Fill both blanks to get the X and Y coordinates of an element's location.

Selenium Java
Point location = element.getLocation();
int x = location.[1]();
int y = location.[2]();
Drag options to blanks, or click blank then click option'
AgetX
BgetY
CgetHeight
DgetWidth
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping getX() and getY()
Using getWidth() or getHeight() which return size, not position
5fill in blank
hard

Fill all three blanks to get the width, height, and Y coordinate of an element.

Selenium Java
Dimension size = element.getSize();
int width = size.[1]();
int height = size.[2]();
int y = element.getLocation().[3]();
Drag options to blanks, or click blank then click option'
AgetX
BgetHeight
CgetY
DgetWidth
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up width and height methods
Using getX() instead of getY() for vertical position