Activity: Locating Elements

Scenario

For a single web page, we will write locators using the different techniques mentioned in this section. For a single web page, we'll locate elements by ID, name, class name, HTML tag, link, xpath, and CSS.

Aim

To create an automation script that uses different kinds of locators to find elements on a web page.

Steps for Completion

  1. Open https://trainingbypackt.github.io/Beginning-Selenium/lesson_3/activity_3_D-1.html and review it.
  2. Using IntelliJ IDEA, import the required packages.
  3. Locate an element by using an ID. Use "lastname" as the ID. Print the output when it's displayed and when it's not.
  4. Locate an element by using a name. Use "hobbies" as the ID. Print the output when it's displayed and when it's not.
  5. Locate an element by using a class name. Use "form-control" as the class name. Print the output when the first name is displayed and when it's not.
  6. Locate an element by using an HTML tag. Use "div" as the class name. Print the output when div.size() > 0 and otherwise.
  7. Locate an element by using a link. Use "Spanish" as the class name. Print the output when link = spanishLink.getAttribute("href") and when it's not.
  8. Locate an element by using xpath. Use "//select" as the xpath. Print the output when dayOfBirth.getOptions().size() > 0 and when this condition is not met.
  9. Locate an element by using CSS. Use "#firstName" as the CSS attribute. Print the output when the first name with the CSS is displayed and when it's not.
  10. Verify that each element was found by interacting with it.
  11. Compile and run the script.

To refer to the detailed steps, go to the Solutions section at the end of 
this book on Page no. 167.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.187.233