0
0
Selenium Javatesting~10 mins

findElement by name 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 name attribute.

Selenium Java
WebElement element = 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.id instead of By.name
Using By.className which looks for class attribute
2fill in blank
medium

Complete the code to click on the element found by name.

Selenium Java
driver.findElement(By.[1]("submitBtn")).click();
Drag options to blanks, or click blank then click option'
Aname
Bid
CcssSelector
Dxpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id or other locators instead of By.name
Forgetting to call click() after finding the element
3fill in blank
hard

Fix the error in the code to correctly find element by name.

Selenium Java
WebElement input = driver.findElement(By.[1]("email"));
Drag options to blanks, or click blank then click option'
Aname
Bid
ClinkText
DclassName
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id or By.className which do not match the name attribute
Using By.linkText which is for links only
4fill in blank
hard

Fill both blanks to create a test that finds an element by name and sends keys.

Selenium Java
WebElement input = driver.findElement(By.[1]("search"));
input.[2]("Selenium");
Drag options to blanks, or click blank then click option'
Aname
BsendKeys
Cclick
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using click() instead of sendKeys() to enter text
Using By.id instead of By.name
5fill in blank
hard

Fill all three blanks to find an element by name, clear it, and enter new text.

Selenium Java
WebElement input = driver.findElement(By.[1]("username"));
input.[2]();
input.[3]("newuser");
Drag options to blanks, or click blank then click option'
Aname
Bclear
CsendKeys
Dclick
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to clear the input before sending keys
Using click() instead of clear() or sendKeys()