0
0
Selenium Javatesting~10 mins

Choosing XPath vs CSS strategy in Selenium Java - Interactive Practice

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

Complete the code to locate an element by CSS selector.

Selenium Java
WebElement button = driver.findElement(By.[1]("button.submit"));
Drag options to blanks, or click blank then click option'
Axpath
Bid
Cname
DcssSelector
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'xpath' when the selector is a CSS selector.
Using 'id' or 'name' methods incorrectly with CSS selector syntax.
2fill in blank
medium

Complete the code to locate an element by XPath.

Selenium Java
WebElement link = driver.findElement(By.[1]("//a[@href='home.html']"));
Drag options to blanks, or click blank then click option'
Axpath
BclassName
Cid
DcssSelector
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cssSelector' with XPath syntax.
Using 'id' or 'className' incorrectly for XPath.
3fill in blank
hard

Fix the error in the locator strategy to find an element by class name.

Selenium Java
WebElement input = driver.findElement(By.[1]("form-input"));
Drag options to blanks, or click blank then click option'
AcssSelector
BclassName
Cxpath
DtagName
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cssSelector' without the '.' prefix for class.
Using 'xpath' when a simpler method exists.
4fill in blank
hard

Fill both blanks to create a CSS selector that finds all div elements with class 'active' and attribute 'data-id' equal to '123'.

Selenium Java
List<WebElement> elements = driver.findElements(By.[1]("div[2][data-id='123']"));
Drag options to blanks, or click blank then click option'
AcssSelector
Bxpath
C.
D#
Attempts:
3 left
💡 Hint
Common Mistakes
Using '#' instead of '.' for class selectors.
Using 'xpath' method with CSS selector syntax.
5fill in blank
hard

Fill all three blanks to write an XPath expression that finds a button element with text 'Submit' and attribute 'type' equal to 'button'.

Selenium Java
WebElement submitBtn = driver.findElement(By.[1]("//[2][[3]='Submit' and @type='button']"));
Drag options to blanks, or click blank then click option'
AcssSelector
Bxpath
Cbutton
Dtext()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cssSelector' with XPath syntax.
Using tag name other than 'button'.
Not using 'text()' to match element text.