Saturday, August 24, 2024

XPath Advanced MCQ

 MCQs on Advanced XPath in Selenium

Which XPath expression selects all child nodes of the current node?


a) //child::*

b) /all-child::*

c) child::*

d) ./child::*

Answer: c) child::*


To select the parent node of the current node, which XPath axis is used?


a) ancestor::

b) preceding::

c) parent::

d) child::

Answer: c) parent::


What does the following XPath expression select: //div/ancestor::body?


a) All body elements that are descendants of div

b) The body element that is an ancestor of any div

c) All div elements within the body element

d) All body elements following div

Answer: b) The body element that is an ancestor of any div


Which XPath expression will select all descendants of a div element?


a) //div/descendant::*

b) /descendant::div

c) descendant::div/*

d) div/descendant::

Answer: a) //div/descendant::*


How would you select all elements that are siblings and appear after a <div> element using XPath?


a) //div/following::*

b) //div/following-sibling::*

c) //div/preceding-sibling::*

d) //div/ancestor::*

Answer: b) //div/following-sibling::*


What does the XPath expression //h2/preceding-sibling::p select?


a) All p elements that are siblings and come before any h2 element

b) All p elements that are children of any h2 element

c) All h2 elements that precede any p element

d) The first p element before each h2

Answer: a) All p elements that are siblings and come before any h2 element



How would you select the second child of a ul element using XPath?


a) //ul/child::li[2]

b) //ul/child::[2]

c) //ul/li[2]

d) //ul/descendant::li[2]

Answer: c) //ul/li[2]


Which XPath axis is used to select all ancestors (parent, grandparent, etc.) of the current node?


a) descendant::

b) ancestor::

c) following::

d) preceding::

Answer: b) ancestor::


What does the XPath expression //a/parent::div select?


a) All a elements that are children of a div

b) All div elements that are parents of an a element

c) All div elements that contain an a element

d) All a elements that are siblings to a div

Answer: b) All div elements that are parents of an a element


How would you select the first td element that is a child of a tr using XPath?


a) //tr/td[1]

b) //tr/child::td[1]

c) //td[1]/parent::tr

d) //tr/child::td[position()=1]

Answer: d) //tr/child::td[position()=1]



What does the XPath //div/following::p[1] select?


a) The first p element that is a sibling following a div

b) The first p element that appears after any div in the document

c) All p elements that appear after a div

d) The first p element that is a child of a div

Answer: b) The first p element that appears after any div in the document


Which XPath expression selects the grandparent of an element with the tag span?


a) //span/ancestor::*[2]

b) //span/parent::*

c) //span/ancestor::*/parent::*

d) //span/ancestor::*/ancestor::*

Answer: a) //span/ancestor::*[2]


To select all nodes that are siblings and precede a <span> element, which XPath axis would you use?


a) preceding-sibling::

b) following-sibling::

c) preceding::

d) ancestor::

Answer: a) preceding-sibling::


How would you use XPath to select all siblings of a div element that come before it in the document?


a) //div/preceding-sibling::*

b) //div/following-sibling::*

c) //div/ancestor::*

d) //div/sibling::*

Answer: a) //div/preceding-sibling::*


What does the expression //input[@type='text']/ancestor::form select?


a) All input elements of type text that are descendants of a form

b) All form elements that are ancestors of input elements of type text

c) The closest form element that is an ancestor of any input of type text

d) All form elements that contain input elements of type text

Answer: b) All form elements that are ancestors of input elements of type text


No comments:

Post a Comment

git commands MCQ

 Here are some multiple-choice questions (MCQs) on Git commands relevant for Selenium: 1. Which Git command is used to clone a remote reposi...