CSS Selectors

 1. How to locate dynamic elements in selenium?

For dynamically changing elements needs to use locators like XPath or CSS locators. So then it is possible to locate the element using stable part of attributes or parent elements

  1. Locate using parent elements
  2. locate using child elements
  3. locate using ancestor elements
  4. locate using descendant elements
  5. Locate using sibling elements
  6. Locate using stable half of the value, id, name or text attributes using starts-with and contains keywords

2. What are the types of selectors supported by Selenium?

  1. id
  2. CSS
  3. class name
  4. XPath
  5. link Text
  6. partial link text
  7. name
  8. tagName

3. What are the advantages of using CSS selectors?

  1. It is a more human-readable format
  2. Well suited for identifying elements based on their classes, id, types, attributes

4. What are the cons of using CSS selectors?

  1. Limited to identify elements based on their relationship like, parent, child, sibling etc…
  2. Cannot traverse in both directions both up and down

5. Identify elements using CSS selectors

  1. tagName[attributeName = ‘attributeValue’]
  2. tagName#idValue
  3. tagName.classValue

6. What is link text?

text available inside <a> tags called link text

<a href="ForgotPassword.php">Forgot Password?</a>
Text: >Forgot Password?<

//element locator
By.linkText("Forgot Password?")
By.partialLinkText("Forgot")

7. What are the tag names of the table?

  1. tr -> table row : By.tagName(“tr”)
  2. td-> table data: By.tagName(“td”)
  3. th-> table header

8. What are the components of HTML?

  1. text
  2. attributes
  3. tags

9. How to find all the links on a web page?

  1. Using anchor tag (a)
List<WebElements> list = driver.findLements(By.tagName(‘a’));

10. What is the difference between ID and name locators?

id: is unique on the given page. so it is easy to identify elements.

name: name is not unique. multiple items can share the same name.


No comments:

Post a Comment

Cucumber

What is Cucumber? Definition : Cucumber is an open-source tool that supports BDD . Purpose : Bridges the communication gap between business ...