0
0
Selenium Javatesting~10 mins

XPath with attributes 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 locate a button with the attribute id='submitBtn'.

Selenium Java
WebElement button = driver.findElement(By.xpath("//button[@[1]='submitBtn']"));
Drag options to blanks, or click blank then click option'
Aclass
Btype
Cname
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'id' when the element has an id attribute.
Using 'name' or 'type' which may not uniquely identify the button.
2fill in blank
medium

Complete the code to find an input element with attribute type='checkbox'.

Selenium Java
WebElement checkbox = driver.findElement(By.xpath("//input[@[1]='checkbox']"));
Drag options to blanks, or click blank then click option'
Aname
Btype
Cvalue
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'name' or 'value' which do not specify the input type.
Using 'id' which may not be present or unique.
3fill in blank
hard

Fix the error in the XPath to select a div with class='container'.

Selenium Java
WebElement container = driver.findElement(By.xpath("//div[@class[1]'container']"));
Drag options to blanks, or click blank then click option'
A==
B!=
C=
D='
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '=' in XPath.
Omitting the equals sign or quotes around the value.
4fill in blank
hard

Fill both blanks to locate an input element with name='email' and type='text'.

Selenium Java
WebElement emailInput = driver.findElement(By.xpath("//input[@[1]='email' and @[2]='text']"));
Drag options to blanks, or click blank then click option'
Aname
Bid
Ctype
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'id' and 'name' attributes.
Using 'value' instead of 'type' for input type.
5fill in blank
hard

Fill all three blanks to find a link (<a>) with href containing 'login' and class='nav-link'.

Selenium Java
WebElement loginLink = driver.findElement(By.xpath("//a[contains(@[1], '[2]') and @[3]='nav-link']"));
Drag options to blanks, or click blank then click option'
Ahref
Blogin
Cclass
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' instead of 'class' for the last attribute.
Using 'href' as the third attribute instead of the first.
Not using 'contains' function properly.