0
0
Selenium Javatesting~10 mins

findElement by xpath 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 XPath using Selenium WebDriver.

Selenium Java
WebElement element = driver.findElement(By.[1]("//button[@id='submit']"));
Drag options to blanks, or click blank then click option'
Axpath
BcssSelector
Cid
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id or By.name instead of By.xpath for XPath expressions.
Using By.cssSelector when the locator is an XPath.
2fill in blank
medium

Complete the code to find an element by XPath that selects an input with a specific placeholder.

Selenium Java
WebElement input = driver.findElement(By.[1]("//input[@placeholder='Search']"));
Drag options to blanks, or click blank then click option'
Axpath
Bid
CclassName
DtagName
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id or By.className when the locator is XPath.
Trying to use By.tagName for attribute-based selection.
3fill in blank
hard

Fix the error in the code to correctly find a button with text 'Submit' using XPath.

Selenium Java
WebElement button = driver.findElement(By.[1]("//button[text()='Submit']"));
Drag options to blanks, or click blank then click option'
AlinkText
BcssSelector
Cxpath
DpartialLinkText
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.cssSelector which cannot select by text content.
Using By.linkText or By.partialLinkText for buttons.
4fill in blank
hard

Fill both blanks to find a div element with class 'container' and attribute 'data-id' equal to '123'.

Selenium Java
WebElement div = driver.findElement(By.[1]("//div[@class=[2] and @data-id='123']"));
Drag options to blanks, or click blank then click option'
Axpath
B"container"
C"container-fluid"
DcssSelector
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.cssSelector with XPath syntax.
Not quoting the class attribute value in XPath.
5fill in blank
hard

Fill all three blanks to find all list items with class 'active' inside an unordered list with id 'menu'.

Selenium Java
List<WebElement> items = driver.findElements(By.[1]("//ul[@id=[2]]/li[@class=[3]]"));
Drag options to blanks, or click blank then click option'
Axpath
B"menu"
C"active"
DcssSelector
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.cssSelector with XPath syntax.
Not quoting attribute values in XPath expression.