0
0
Selenium Javatesting~10 mins

findElement by cssSelector 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 CSS selector.

Selenium Java
WebElement element = driver.findElement(By.[1](".button"));
Drag options to blanks, or click blank then click option'
Axpath
BcssSelector
Cname
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using id or name instead of cssSelector for CSS selectors.
2fill in blank
medium

Complete the code to find an element with class 'active' using CSS selector.

Selenium Java
WebElement activeElement = driver.findElement(By.[1](".active"));
Drag options to blanks, or click blank then click option'
AcssSelector
Bid
CtagName
DlinkText
Attempts:
3 left
💡 Hint
Common Mistakes
Using id or tagName instead of cssSelector.
3fill in blank
hard

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

Selenium Java
WebElement element = driver.findElement(By.[1]("#submit-btn"));
Drag options to blanks, or click blank then click option'
AcssSelector
Bname
CclassName
Dxpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using name or className for CSS selectors with #.
4fill in blank
hard

Fill both blanks to find an element with tag 'input' and attribute 'type' equals 'text' using CSS selector.

Selenium Java
WebElement inputField = driver.findElement(By.[1]("[2]"));
Drag options to blanks, or click blank then click option'
AcssSelector
Binput[type='text']
Cxpath
DclassName
Attempts:
3 left
💡 Hint
Common Mistakes
Using xpath or className instead of cssSelector.
Incorrect CSS selector syntax.
5fill in blank
hard

Fill all three blanks to find a button element with class 'submit' and text 'Send' using CSS selector.

Selenium Java
WebElement sendButton = driver.findElement(By.[1]("[2]"));
String buttonText = sendButton.getText();
assertEquals("[3]", buttonText);
Drag options to blanks, or click blank then click option'
AcssSelector
Bbutton.submit
CSend
Dxpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using xpath instead of cssSelector.
Incorrect CSS selector syntax.
Wrong expected text in assertion.