MCQs on CSS Selector Handling Using Selenium Java
What does a CSS selector of #username select?
a) All elements with the class name username
b) All elements with the tag name username
c) The element with the ID username
d) The first element containing the text username
Answer: c) The element with the ID username
Which CSS selector is used to select elements with a specific class name?
a) #classname
b) .classname
c) @classname
d) classname
Answer: b) .classname
What does the CSS selector input[type='text'] select?
a) All input elements of type text
b) All elements with an attribute type='text'
c) The first input element of type text
d) All elements containing the text "text"
Answer: a) All input elements of type text
Which CSS selector would you use to select a direct child element li of an ul?
a) ul > li
b) ul + li
c) ul li
d) ul:li
Answer: a) ul > li
What does the CSS selector a[href*='login'] select?
a) All anchor elements whose href attribute contains the text login
b) All anchor elements whose href attribute starts with login
c) All elements whose href contains login
d) All anchor elements with an exact href match to login
Answer: a) All anchor elements whose href attribute contains the text login
How can you select an element that is both a div and has the class container?
a) div container
b) div.container
c) .div.container
d) div#container
Answer: b) div.container
Which CSS selector is used to select all p elements that are descendants of a div?
a) div p
b) div > p
c) div + p
d) p < div
Answer: a) div p
Which of the following CSS selectors will select an element with an attribute data-role='admin'?
a) *[data-role='admin']
b) *[role='admin']
c) *[data-admin='role']
d) *[data-role="admin"]
Answer: d) *[data-role="admin"]
To select every nth child element of a parent, which CSS pseudo-class would you use?
a) :nth-child(n)
b) :nth-of-type(n)
c) :nth-element(n)
d) :nth-child-of(n)
Answer: a) :nth-child(n)
How would you select an element using a partial match on the class name?
a) .classname*='partial'
b) [class*='partial']
c) .classname[partial]
d) [classname^='partial']
Answer: b) [class*='partial']
Which CSS selector would you use to select all elements with a specific attribute name, regardless of the attribute value?
a) [*]
b) [attribute]
c) [attribute*]
d) [*=attribute]
Answer: b) [attribute]
How do you select all div elements with a class name that ends with "content"?
a) div[class$='content']
b) div[.content]
c) div[class^='content']
d) div[class*='content']
Answer: a) div[class$='content']
How would you select the second li element that is a child of an ol?
a) ol li:nth-child(2)
b) ol > li:nth-child(2)
c) ol:nth-child(2)
d) li:nth-child(2)
Answer: b) ol > li:nth-child(2)
What does the CSS selector a[target='_blank'] select?
a) All anchor elements
b) All anchor elements with a target attribute
c) All anchor elements with target='_blank'
d) All elements with a target='_blank'
Answer: c) All anchor elements with target='_blank'
No comments:
Post a Comment