0
0
Selenium Javatesting~10 mins

findElement by ID 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 find an element by its ID using Selenium WebDriver.

Selenium Java
WebElement element = driver.findElement(By.[1]("submitBtn"));
Drag options to blanks, or click blank then click option'
Aname
BclassName
Cid
DtagName
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.name instead of By.id when the locator is an ID.
Using incorrect locator methods like By.className for an ID.
2fill in blank
medium

Complete the code to click on a button found by its ID.

Selenium Java
driver.findElement(By.[1]("loginButton")).click();
Drag options to blanks, or click blank then click option'
AcssSelector
Bid
Cxpath
DlinkText
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.cssSelector or By.xpath when the ID locator is simpler.
Trying to click before finding the element.
3fill in blank
hard

Fix the error in the code to correctly find an element by ID.

Selenium Java
WebElement input = driver.findElement(By.[1]("userName"));
Drag options to blanks, or click blank then click option'
Aid
Bname
CclassName
DtagName
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.name or By.className when the element is identified by ID.
Misspelling the locator method.
4fill in blank
hard

Fill both blanks to find an element by ID and get its text.

Selenium Java
String text = driver.findElement(By.[1]("message")).[2]();
Drag options to blanks, or click blank then click option'
Aid
BgetText
Cclick
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using click() instead of getText() when trying to read text.
Using By.name instead of By.id.
5fill in blank
hard

Fill all three blanks to find an element by ID, clear its content, and enter new text.

Selenium Java
WebElement input = driver.findElement(By.[1]("searchBox"));
input.[2]();
input.[3]("Selenium testing");
Drag options to blanks, or click blank then click option'
Aid
Bclear
CsendKeys
Dclick
Attempts:
3 left
💡 Hint
Common Mistakes
Using click() instead of clear() before typing.
Using wrong locator methods like By.name.
Forgetting to clear the input before sending keys.