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


Web Tables Using Selenium Java MCQ

 MCQs on Handling Web Tables Using Selenium Java

Which method is commonly used to locate a web table on a webpage in Selenium?


a) findElement(By.table)

b) findElement(By.xpath)

c) findElement(By.tagName("table"))

d) findElement(By.className("webtable"))

Answer: c) findElement(By.tagName("table"))


How do you retrieve all rows of a web table using Selenium WebDriver?


a) findElements(By.tagName("row"))

b) findElements(By.tagName("tr"))

c) findElement(By.xpath("//tr"))

d) findElements(By.xpath("//td"))

Answer: b) findElements(By.tagName("tr"))


To get the number of columns in the first row of a web table, which code snippet is correct?


a) List<WebElement> cols = table.findElements(By.xpath(".//tr[0]/td"));

b) List<WebElement> cols = table.findElements(By.xpath(".//tr[1]/td"));

c) List<WebElement> cols = table.findElements(By.tagName("th"));

d) List<WebElement> cols = table.findElements(By.xpath(".//tr[1]/th"));

Answer: b) List<WebElement> cols = table.findElements(By.xpath(".//tr[1]/td"));


What is the correct way to iterate through all rows in a web table?


a) for(WebElement row : table.findElements(By.tagName("tr")))

b) for(WebElement row : table.findElements(By.tagName("td")))

c) for(WebElement row : driver.findElements(By.tagName("tr")))

d) for(WebElement row : driver.findElements(By.xpath("//table/tr")))

Answer: a) for(WebElement row : table.findElements(By.tagName("tr")))


Which XPath would correctly locate the third cell in the second row of a web table?


a) //table/tr[2]/td[3]

b) //table/tbody/tr[2]/td[3]

c) //table//tr[3]/td[2]

d) //table//tr[2]//td[3]

Answer: b) //table/tbody/tr[2]/td[3]


How can you check if a particular text exists in a web table cell?


a) if(cell.getText().contains("text"))

b) if(cell.hasText("text"))

c) if(cell.findElement(By.text("text")))

d) if(cell.equals("text"))

Answer: a) if(cell.getText().contains("text"))


To handle dynamic web tables, which approach is commonly used?


a) Use driver.switchTo().frame()

b) Use dynamic XPath with conditions

c) Use findElement with By.cssSelector

d) Use static By.id locator

Answer: b) Use dynamic XPath with conditions


How would you identify a specific row in a web table based on its content?


a) driver.findElement(By.xpath("//tr[contains(text(),'content')]"))

b) table.findElement(By.xpath(".//tr[.//td[text()='content']]"))

c) driver.findElement(By.xpath("//tr[text()='content']"))

d) table.findElements(By.cssSelector("tr:contains('content')"))

Answer: b) table.findElement(By.xpath(".//tr[.//td[text()='content']]"))


What is the best way to handle pagination while iterating through all rows of a web table?


a) Click on all pages and extract rows individually

b) Use JavaScript to load all rows

c) Set the page size to display all rows

d) Combine a loop to navigate pages with row extraction

Answer: d) Combine a loop to navigate pages with row extraction


How do you extract the text from the first cell of each row in a web table?


a) for(WebElement row : rows) { System.out.println(row.findElement(By.xpath(".//td[1]")).getText()); }

b) for(WebElement row : rows) { System.out.println(row.findElement(By.cssSelector("td:first-child")).getText()); }

c) for(WebElement row : rows) { System.out.println(row.findElement(By.tagName("td[1]")).getText()); }

d) Both a) and b) are correct

Answer: d) Both a) and b) are correct


To find the total number of rows in a web table, which of the following is used?


a) table.getRows().size()

b) table.findElements(By.tagName("row")).size()

c) table.findElements(By.tagName("tr")).size()

d) table.findElements(By.xpath(".//td")).size()

Answer: c) table.findElements(By.tagName("tr")).size()


How can you identify a table cell with a specific class attribute?


a) table.findElement(By.cssSelector("td.classname"))

b) table.findElement(By.xpath("//td[@class='classname']"))

c) table.findElement(By.className("classname"))

d) Both b) and c)

Answer: d) Both b) and c)  (Recheck - all options are right)


Which method would you use to interact with a checkbox within a table cell?


a) findElement(By.xpath(".//input[@type='checkbox']")).click()

b) findElement(By.xpath("//checkbox")).click()

c) findElement(By.xpath(".//checkbox")).click()

d) findElement(By.tagName("checkbox")).click()

Answer: a) findElement(By.xpath(".//input[@type='checkbox']")).click()


If you need to select the last row of a web table using XPath, which syntax would you use?


a) //table/tr[last()]

b) //table/tbody/tr[last()]

c) //table//tr[last()]

d) All of the above

Answer: d) All of the above



Which Selenium command is used to find multiple elements, like all cells in a specific column?


a) driver.findElements(By.tagName("td"))

b) driver.findElement(By.xpath("//td"))

c) driver.findElements(By.cssSelector("td"))

d) Both a) and c)

Answer: d) Both a) and c)


What is the primary challenge in automating dynamic web tables?


a) Locating static elements

b) Managing dynamic row and column indices

c) Handling static web tables

d) Finding the table tag

Answer: b) Managing dynamic row and column indices


When handling web tables with Selenium, what does //table/tbody/tr/td select?


a) All rows of the table

b) All table cells in all rows

c) Only the first cell in each row

d) Only the header cells of the table

Answer: b) All table cells in all rows


To select the header row of a table using XPath, which expression would you use?


a) //table/th

b) //table/thead/tr

c) //table/thead/th

d) //table/tbody/th

Answer: b) //table/thead/tr


How can you identify a row containing a specific text within any of its cells?


a) //tr[td[contains(text(),'specific text')]]

b) //tr[contains(., 'specific text')]

c) //tr/td[contains(text(), 'specific text')]

d) Both a) and b)

Answer: d) Both a) and b) Recheck - answer - c

Keyboard operations using Actions MCQ

 MCQs on Enter, Control, and Shift Keys Using Actions Class in Selenium Java

Which method in the Actions class is used to simulate pressing the Enter key?


a) sendKeys(Keys.ENTER)

b) keyPress(Keys.ENTER)

c) keyDown(Keys.ENTER)

d) pressEnter()

Answer: a) sendKeys(Keys.ENTER)


How do you simulate holding down the Control key using the Actions class?


a) controlDown(Keys.CONTROL)

b) keyDown(Keys.CONTROL)

c) sendKeys(Keys.CONTROL)

d) pressControl(Keys.CONTROL)

Answer: b) keyDown(Keys.CONTROL)


To simulate releasing the Shift key after pressing it, which method should be used?


a) releaseShift(Keys.SHIFT)

b) keyRelease(Keys.SHIFT)

c) keyUp(Keys.SHIFT)

d) pressShift(Keys.SHIFT)

Answer: c) keyUp(Keys.SHIFT)


Which of the following code snippets simulates typing text in uppercase using the Actions class?


a) actions.keyDown(Keys.SHIFT).sendKeys("hello").keyUp(Keys.SHIFT).perform();

b) actions.sendKeys(Keys.SHIFT, "HELLO").perform();

c) actions.shiftAndType("HELLO").perform();

d) actions.sendKeys("HELLO").perform();


Answer: a) actions.keyDown(Keys.SHIFT).sendKeys("hello").keyUp(Keys.SHIFT).perform();


What is the correct sequence to perform a Ctrl + A operation using the Actions class?


a) actions.sendKeys(Keys.CONTROL, "A").perform();

b) actions.keyDown(Keys.CONTROL).sendKeys("A").keyUp(Keys.CONTROL).perform();

c) actions.pressControl("A").perform();

d) actions.sendKeys(Keys.CONTROL + "A").perform();

Answer: b) actions.keyDown(Keys.CONTROL).sendKeys("A").keyUp(Keys.CONTROL).perform();


Which method combination would you use to simulate pressing and releasing the Enter key on a specific WebElement?


a) element.sendKeys(Keys.ENTER)

b) actions.sendKeys(element, Keys.ENTER).perform();

c) actions.keyDown(element, Keys.ENTER).keyUp(element, Keys.ENTER).perform();

d) actions.pressAndRelease(Keys.ENTER).perform();

Answer: b) actions.sendKeys(element, Keys.ENTER).perform();


How do you perform a Ctrl + Click action on an element using the Actions class?


a) actions.sendKeys(Keys.CONTROL).click(element).perform();

b) actions.keyDown(Keys.CONTROL).click(element).keyUp(Keys.CONTROL).perform();

c) actions.ctrlClick(element).perform();

d) actions.keyPress(Keys.CONTROL).click(element).perform();

Answer: b) actions.keyDown(Keys.CONTROL).click(element).keyUp(Keys.CONTROL).perform();


What is the result of calling keyUp(Keys.CONTROL) in the Actions class without a preceding keyDown(Keys.CONTROL)?


a) Nothing happens; it does not affect the state.

b) It releases the Control key regardless of its state.

c) It throws an exception.

d) It performs a Control key release only if the Control key is pressed.

Answer: b) It releases the Control key regardless of its state.


How do you perform a Shift + Enter key combination using the Actions class?


a) actions.sendKeys(Keys.SHIFT, Keys.ENTER).perform();

b) actions.keyDown(Keys.SHIFT).sendKeys(Keys.ENTER).keyUp(Keys.SHIFT).perform();

c) actions.keyPress(Keys.SHIFT).keyPress(Keys.ENTER).perform();

d) actions.shiftEnter().perform();

Answer: b) actions.keyDown(Keys.SHIFT).sendKeys(Keys.ENTER).keyUp(Keys.SHIFT).perform();


Which method should be used to simulate the pressing of multiple keys at once, like Ctrl + Shift?


a) sendKeys(Keys.CONTROL, Keys.SHIFT)

b) keyDown(Keys.CONTROL).keyDown(Keys.SHIFT)

c) pressKeys(Keys.CONTROL, Keys.SHIFT)

d) keyPress(Keys.CONTROL, Keys.SHIFT)

Answer: b) keyDown(Keys.CONTROL).keyDown(Keys.SHIFT)


To simulate typing "Hello" followed by pressing Enter, which Actions class method is correct?


a) actions.sendKeys("Hello", Keys.ENTER).perform();

b) actions.sendKeys("Hello").sendKeys(Keys.ENTER).perform();

c) actions.type("Hello").pressEnter().perform();

d) actions.sendKeys("Hello" + Keys.ENTER).perform();

Answer: b) actions.sendKeys("Hello").sendKeys(Keys.ENTER).perform();


How do you use the Actions class to select text using Shift + Arrow keys?


a) actions.keyDown(Keys.SHIFT).sendKeys(Keys.ARROW_LEFT).keyUp(Keys.SHIFT).perform();

b) actions.pressAndHold(Keys.SHIFT).sendKeys(Keys.ARROW_LEFT).perform();

c) actions.keyPress(Keys.SHIFT).sendKeys(Keys.ARROW_LEFT).perform();

d) actions.sendKeys(Keys.SHIFT + Keys.ARROW_LEFT).perform();

Answer: a) actions.keyDown(Keys.SHIFT).sendKeys(Keys.ARROW_LEFT).keyUp(Keys.SHIFT).perform();


Which Actions method is used to simulate pressing the Control key on the keyboard?


a) keyPress(Keys.CONTROL)

b) keyDown(Keys.CONTROL)

c) pressControl(Keys.CONTROL)

d) sendKeys(Keys.CONTROL)

Answer: b) keyDown(Keys.CONTROL)


How do you simulate pressing Ctrl + V (paste operation) using the Actions class?


a) actions.sendKeys(Keys.CONTROL, "v").perform();

b) actions.keyDown(Keys.CONTROL).sendKeys("v").keyUp(Keys.CONTROL).perform();

c) actions.ctrlPaste().perform();

d) actions.keyPress(Keys.CONTROL, "v").perform();

Answer: b) actions.keyDown(Keys.CONTROL).sendKeys("v").keyUp(Keys.CONTROL).perform();


Which method is used to release all modifier keys that are currently pressed?


a) releaseAllKeys()

b) keyUpAll()

c) releaseKeys()

d) sendKeys(Keys.NULL)

Answer: d) sendKeys(Keys.NULL)


What is the proper way to simulate holding down both Ctrl and Shift and then pressing the Enter key?


a) actions.keyDown(Keys.CONTROL).keyDown(Keys.SHIFT).sendKeys(Keys.ENTER).perform();

b) actions.sendKeys(Keys.CONTROL, Keys.SHIFT, Keys.ENTER).perform();

c) actions.controlShiftEnter().perform();

d) actions.keyDown(Keys.CONTROL + Keys.SHIFT).sendKeys(Keys.ENTER).perform();

Answer: a) actions.keyDown(Keys.CONTROL).keyDown(Keys.SHIFT).sendKeys(Keys.ENTER).perform();


Which Actions method simulates a key release of the Enter key after being pressed?


a) release(Keys.ENTER)

b) keyUp(Keys.ENTER)

c) releaseEnterKey()

d) keyRelease(Keys.ENTER)

Answer: b) keyUp(Keys.ENTER)


How would you use the Actions class to perform Shift + Click on a web element?


a) actions.keyDown(Keys.SHIFT).click(element).keyUp(Keys.SHIFT).perform();

b) actions.shiftClick(element).perform();

c) actions.keyDown(element, Keys.SHIFT).click(element).keyUp(element, Keys.SHIFT).perform();

d) actions.click(Keys.SHIFT).click(element).perform();

Answer: a) actions.keyDown(Keys.SHIFT).click(element).keyUp(Keys.SHIFT).perform();


To simulate the pressing of Enter on a form field, which combination of methods is appropriate?


a) element.sendKeys(Keys.ENTER)

b) actions.click(element).sendKeys(Keys.ENTER).perform();

c) actions.sendKeys(element, Keys.ENTER).perform();

d) element.pressEnter();

Answer: c) actions.sendKeys(element, Keys.ENTER).perform();


What would be the result of executing actions.sendKeys(Keys.CONTROL + "a").perform();?


a) It performs a Ctrl + A operation to select all content.

b) It throws an exception.

c) It sends the literal string Keys.CONTROL + "a" to the active element.

d) It performs no operation as + is not a valid combination.

Answer: c) It sends the literal string Keys.CONTROL + "a" to the active element.

Actions Using Selenium Java MCQ

 MCQs on Actions Using Selenium Java

Which class in Selenium is used for performing complex user interactions such as mouse and keyboard actions?


a) WebElement

b) Action

c) Actions

d) Interactions

Answer: c) Actions


What is the correct way to initialize the Actions class in Selenium Java?


a) Actions actions = new Actions(driver);

b) Actions action = new Actions();

c) Actions actions = new Action(driver);

d) Action actions = new Actions(driver);

Answer: a) Actions actions = new Actions(driver);


Which method is used to perform a right-click action on a web element using the Actions class?


a) actions.contextClick()

b) actions.rightClick()

c) actions.click()

d) actions.doubleClick()

Answer: a) actions.contextClick()


How do you perform a double-click action on an element using the Actions class?


a) actions.doubleClick(element).perform();

b) actions.clickTwice(element).perform();

c) actions.doubleClick().perform();

d) actions.click(element).perform();

Answer: a) actions.doubleClick(element).perform();


Which method is used to click and hold a web element using the Actions class?


a) clickAndHold(element)

b) holdClick(element)

c) clickHold(element)

d) holdClickAndDrag(element)

Answer: a) clickAndHold(element)


What is the purpose of the build() method in the Actions class?


a) To execute multiple actions

b) To combine multiple actions into a single action

c) To build the Actions class object

d) To reset the actions sequence

Answer: b) To combine multiple actions into a single action


How do you drag and drop an element from one location to another using the Actions class?


a) actions.dragAndDrop(source, target).perform();

b) actions.dragDrop(source, target).perform();

c) actions.moveTo(source).moveTo(target).release().perform();

d) actions.clickAndHold(source).moveToElement(target).release().perform();

Answer: a) actions.dragAndDrop(source, target).perform();


Which method moves the mouse to the middle of the specified element?


a) moveToElement(element)

b) hoverOverElement(element)

c) moveToMiddle(element)

d) hoverToElement(element)

Answer: a) moveToElement(element)


How do you perform a series of actions like click, hold, and release in Selenium?


a) actions.click().hold().release().perform();

b) actions.clickAndHold().moveByOffset(10, 10).release().perform();

c) actions.sequenceClickHoldRelease().perform();

d) actions.pressAndRelease().perform();

Answer: b) actions.clickAndHold().moveByOffset(10, 10).release().perform();


Which method is used to perform a keyboard key press using the Actions class?


a) sendKeys(Keys.KEY)

b) keyDown(Keys.KEY)

c) pressKey(Keys.KEY)

d) keyPress(Keys.KEY)

Answer: b) keyDown(Keys.KEY)


How do you release a key that was pressed down using the Actions class?


a) keyRelease(Keys.KEY)

b) releaseKey(Keys.KEY)

c) keyUp(Keys.KEY)

d) release(Keys.KEY)

Answer: c) keyUp(Keys.KEY)


Which method is used to move the mouse to an offset from the current location?


a) moveByOffset(x, y)

b) moveToOffset(x, y)

c) mouseMove(x, y)

d) moveOffset(x, y)

Answer: a) moveByOffset(x, y)


Which method in the Actions class is used to perform all actions that are queued?


a) execute()

b) perform()

c) run()

d) commit()

Answer: b) perform()


Which exception might be thrown if the perform() method is called on a sequence of actions that includes a move to an element that is not interactable?


a) ElementNotInteractableException

b) ActionNotCompletedException

c) ElementNotVisibleException

d) InvalidActionException

Answer: a) ElementNotInteractableException


What does the sendKeys() method in the Actions class do?


a) Sends keyboard input to the currently focused element

b) Simulates typing keys on the keyboard

c) Performs key up and key down actions

d) Sends keys directly to a specified element

Answer: b) Simulates typing keys on the keyboard


How do you perform a click-and-hold action on a web element using the Actions class?


a) clickAndHold(element)

b) clickHold(element)

c) holdClick(element)

d) clickAndDrag(element)

Answer: a) clickAndHold(element)


What method would you use to hover over an element and display a dropdown menu using the Actions class?


a) hoverOverElement(element)

b) moveToElement(element)

c) clickAndHold(element)

d) hoverAndShow(element)

Answer: b) moveToElement(element)


To perform a keyboard shortcut (e.g., Ctrl + A), which Actions method combination is correct?


a) keyDown(Keys.CONTROL).sendKeys("A").keyUp(Keys.CONTROL).perform();

b) pressKey(Keys.CONTROL + "A").perform();

c) sendKeys(Keys.CONTROL, "A").perform();

d) shortcut(Keys.CONTROL, "A").perform();

Answer: a) keyDown(Keys.CONTROL).sendKeys("A").keyUp(Keys.CONTROL).perform();


Which method combination would you use to click and drag an element to a target location using the Actions class?


a) clickAndHold(element).moveToElement(target).release().perform();

b) clickAndHold(element).dragTo(target).release().perform();

c) dragAndDrop(element, target).perform();

d) moveElementTo(element, target).perform();

Answer: a) clickAndHold(element).moveToElement(target).release().perform();


Which method in the Actions class would you use to perform a sequence of keyboard and mouse actions?


a) sendKeysAndClick()

b) performSequence()

c) build()

d) keyAndMouseSequence()

Answer: c) build()

Handling Multi-Select Dropdowns Using Selenium Java MCQ

 MCQs on Handling Multi-Select Dropdowns Using Selenium Java

Which class in Selenium is used to handle multi-select dropdowns?


a) WebElement

b) MultiSelect

c) Select

d) Dropdown

Answer: c) Select


How do you verify if a dropdown allows multiple selections?


a) dropdown.isMultiple()

b) dropdown.isMultiSelect()

c) dropdown.isMultipleSelect()

d) dropdown.isSelectable()

Answer: a) dropdown.isMultiple()


Which method is used to select multiple options in a dropdown by their visible text?


a) selectByText()

b) selectByVisibleText()

c) selectMultipleByText()

d) selectByValue()

Answer: b) selectByVisibleText()


How can you select multiple options in a dropdown by their values using Selenium?


a) selectByMultipleValues()

b) selectByValue("value1"); selectByValue("value2");

c) selectByIndex(1, 2)

d) selectMultipleOptions()

Answer: b) selectByValue("value1"); selectByValue("value2");


Which method would you use to deselect all selected options in a multi-select dropdown?


a) clearAllSelections()

b) deselectAll()

c) removeAllSelections()

d) clearSelections()

Answer: b) deselectAll()


What is the method to deselect an option in a multi-select dropdown by its index?


a) deselectByIndex()

b) removeByIndex()

c) deselectOptionByIndex()

d) clearByIndex()

Answer: a) deselectByIndex()


Which method is used to deselect an option by its visible text in a multi-select dropdown?


a) deselectByValue()

b) deselectByText()

c) deselectByVisibleText()

d) clearByVisibleText()

Answer: c) deselectByVisibleText()


How do you retrieve all selected options from a multi-select dropdown?


a) getAllSelectedOptions()

b) getSelectedOptions()

c) getAllOptions()

d) getFirstSelectedOption()

Answer: a) getAllSelectedOptions()


Which method will throw an exception if the multi-select dropdown does not have the specified option?


a) selectByIndex()

b) selectByValue()

c) selectByVisibleText()

d) All of the above

Answer: d) All of the above


What exception is thrown when trying to deselect an option from a single-select dropdown?


a) InvalidOperationException

b) UnsupportedOperationException

c) NotImplementedException

d) NoSuchElementException

Answer: b) UnsupportedOperationException


To select multiple options using Selenium in a multi-select dropdown, which looping structure is commonly used?


a) for loop

b) while loop

c) do-while loop

d) for-each loop

Answer: d) for-each loop


Which Selenium method checks if an option in a multi-select dropdown is selected?


a) isOptionSelected()

b) isSelected()

c) isMultiSelected()

d) isMultiple()

Answer: b) isSelected()


How would you deselect an option in a multi-select dropdown by its value?


a) deselectByText()

b) deselectByValue()

c) deselectByOptionValue()

d) removeByValue()

Answer: b) deselectByValue()


Which method retrieves the first selected option from a multi-select dropdown?


a) getFirstSelectedOption()

b) getSelectedOption()

c) getAllSelectedOptions()

d) getFirstOption()

Answer: a) getFirstSelectedOption()


How do you check if a dropdown element is a multi-select dropdown before performing operations?


a) if (dropdown.isMulti())

b) if (dropdown.isMultiple())

c) if (dropdown.isMultiSelect())

d) if (dropdown.isEnabled())

Answer: b) if (dropdown.isMultiple())


In a multi-select dropdown, what is the default behavior of deselectAll()?


a) Deselects all selected options

b) Throws an exception if there are no selected options

c) Selects all options

d) Does nothing

Answer: a) Deselects all selected options


Which method in the Select class is not applicable to single-select dropdowns?


a) selectByVisibleText()

b) selectByValue()

c) deselectAll()

d) selectByIndex()

Answer: c) deselectAll()


What is the return type of getAllSelectedOptions() in Selenium?


a) List<WebElement>

b) WebElement

c) ArrayList<WebElement>

d) Set<WebElement>

Answer: a) List<WebElement>


When using isMultiple() in Selenium, what does it check?


a) If multiple dropdowns exist on the page

b) If the dropdown allows multiple selections

c) If more than one option is selected

d) If the dropdown is visible

Answer: b) If the dropdown allows multiple selections

Handling Dropdowns or List Boxes Using Selenium Java MCQ

 MCQs on Handling Dropdowns or List Boxes Using Selenium Java

Which Selenium class is specifically used for handling dropdowns in Java?


a) WebElement

b) Select

c) Dropdown

d) WebDriver

Answer: b) Select


What is the correct way to initialize a dropdown using Selenium's Select class in Java?


a) Select dropdown = new Select(driver.findElement(By.id("dropdownId")));

b) WebElement dropdown = driver.findElement(By.id("dropdownId"));

c) Dropdown dropdown = new Select(driver.findElement(By.id("dropdownId")));

d) Select dropdown = driver.findElement(By.id("dropdownId"));

Answer: a) Select dropdown = new Select(driver.findElement(By.id("dropdownId")));


Which method is used to select an option from a dropdown by its visible text?


a) selectByValue()

b) selectByVisibleText()

c) selectByIndex()

d) getOptions()

Answer: b) selectByVisibleText()


How can you select an option from a dropdown by its index?


a) dropdown.selectByText(int index);

b) dropdown.selectByIndex(int index);

c) dropdown.selectByValue(int index);

d) dropdown.selectByVisibleText(int index);

Answer: b) dropdown.selectByIndex(int index);


Which method is used to select an option from a dropdown by its value attribute?


a) selectByText()

b) selectByVisibleText()

c) selectByIndex()

d) selectByValue()

Answer: d) selectByValue()


What is the method to retrieve all options available in a dropdown?


a) getAllOptions()

b) getOptions()

c) retrieveOptions()

d) getAvailableOptions()

Answer: b) getOptions()


How can you retrieve the first selected option from a dropdown using Selenium?


a) getFirstSelectedOption()

b) getSelectedOption()

c) getFirstOption()

d) getFirstSelected()

Answer: a) getFirstSelectedOption()


What will the isMultiple() method of the Select class return?


a) true if the dropdown allows multiple selections

b) false if the dropdown allows multiple selections

c) The number of options in the dropdown

d) null if no option is selected

Answer: a) true if the dropdown allows multiple selections


Which exception is thrown if an option is not found in the dropdown?


a) NoSuchElementException

b) ElementNotFoundException

c) NoSuchOptionException

d) OptionNotFoundException

Answer: a) NoSuchElementException


How do you deselect all selected options in a multi-select dropdown?


a) deselectAll()

b) deselectOptions()

c) clearSelections()

d) deselectAllOptions()

Answer: a) deselectAll()


Which method would you use to deselect an option by its index in a multi-select dropdown?


a) deselectByText(int index)

b) deselectByIndex(int index)

c) deselectByValue(int index)

d) deselectByVisibleText(int index)

Answer: b) deselectByIndex(int index)


How do you verify if a dropdown is a multi-select dropdown?


a) Use the getOptions() method

b) Use the isMultiple() method

c) Use the checkMultiSelect() method

d) Use the isMultiSelect() method

Answer: b) Use the isMultiple() method


What is the purpose of the deselectByVisibleText() method in a multi-select dropdown?


a) To select an option by its visible text

b) To deselect an option by its value

c) To deselect an option by its visible text

d) To remove all selections

Answer: c) To deselect an option by its visible text


If you want to select multiple options in a dropdown by their values, which method would you use?


a) selectByValue(String value1, String value2)

b) selectByMultipleValues(List<String> values)

c) selectByValue() in a loop

d) selectMultipleValues()

Answer: c) selectByValue() in a loop


How would you handle a scenario where the dropdown options are dynamically loaded after a delay?


a) Use Thread.sleep() to wait for the options to load

b) Use WebDriverWait with ExpectedConditions.elementToBeClickable()

c) Use driver.refresh() to reload the page

d) Use selectByIndex() method


Answer: b) Use WebDriverWait with ExpectedConditions.elementToBeClickable()


Which method of the Select class would you use to deselect all options by visible text?


a) deselectAll()

b) deselectByVisibleText()

c) deselectAllByVisibleText()

d) clearSelections()

Answer: b) deselectByVisibleText()


What is the correct syntax to select an option using the value attribute in a dropdown?


a) selectByValue("value");

b) selectByVisibleText("value");

c) selectOptionByValue("value");

d) selectValue("value");

Answer: a) selectByValue("value");


To verify if a specific option is selected in a dropdown, which method would you use?


a) isOptionSelected()

b) getFirstSelectedOption()

c) isSelected()

d) isMultiple()

Answer: b) getFirstSelectedOption()



How can you verify that a dropdown does not allow multiple selections?


a) Use the isMultiple() method and check for false

b) Use the isSingle() method

c) Check if getOptions() returns more than one option

d) Use the verifySingleSelection() method

Answer: a) Use the isMultiple() method and check for false

Differences Between findElement() and findElements() in Selenium Java MCQ

MCQs on Differences Between findElement() and findElements() in Selenium Java

What is the primary difference between findElement() and findElements() in Selenium?


a) findElement() returns a list of elements, while findElements() returns a single element.

b) findElement() returns a single WebElement, while findElements() returns a List<WebElement>.

c) findElement() throws an exception if no elements are found, while findElements() returns null.

d) findElement() can find hidden elements, while findElements() cannot.


Answer: b) findElement() returns a single WebElement, while findElements() returns a List<WebElement>.


What does the findElement() method return if no element is found?


a) null

b) An empty list

c) NoSuchElementException

d) A new instance of WebElement


Answer: c) NoSuchElementException


Which method would you use if you need to find and interact with multiple elements on a webpage?


a) findElement()

b) findElements()

c) getElement()

d) getElements()


Answer: b) findElements()


If you want to check whether an element exists on a webpage without causing an exception, which method should you use?


a) findElement()

b) findElements()

c) getElementById()

d) elementExists()


Answer: b) findElements()


What is returned by findElements() if no matching elements are found?


a) null

b) NoSuchElementException

c) StaleElementReferenceException

d) An empty list


Answer: d) An empty list


Which of the following statements is true regarding findElement()?


a) It always returns a list, even if only one element is found.

b) It throws a NoSuchElementException if no element is found.

c) It returns the first element it finds and stops searching.

d) It returns all elements that match the locator.


Answer: b) It throws a NoSuchElementException if no element is found.


If you want to find all elements with the class name "button" on a webpage, which method should you use?


a) driver.findElement(By.className("button"));

b) driver.findElements(By.className("button"));

c) driver.findElement(By.name("button"));

d) driver.findElements(By.tagName("button"));


Answer: b) driver.findElements(By.className("button"));


Which method is more efficient if you are only looking for the first occurrence of an element?


a) findElement()

b) findElements()

c) Both are equally efficient.

d) It depends on the locator used.


Answer: a) findElement()


When would you use findElements() over findElement()?


a) When you expect only one element to be present.

b) When you need to check for the presence of an element without throwing an exception.

c) When you want to find the first matching element.

d) When you need to perform an action on the first matching element.


Answer: b) When you need to check for the presence of an element without throwing an exception.


What type of collection does findElements() return?


a) Set<WebElement>

b) Map<WebElement>

c) List<WebElement>

d) Queue<WebElement>


Answer: c) List<WebElement>


What happens if findElement() finds multiple elements that match the locator?


a) It throws an ElementNotVisibleException.

b) It throws a NoSuchElementException.

c) It returns the first matching WebElement.

d) It returns all matching elements in a list.


Answer: c) It returns the first matching WebElement.


How would you handle a situation where you are not sure if an element exists on the page?


a) Use findElement() and handle the exception.

b) Use findElements() and check if the returned list is empty.

c) Use getElementById() method.

d) Use findElement() and check if it returns null.


Answer: b) Use findElements() and check if the returned list is empty.


What is a common use case for findElements() in Selenium testing?


a) To perform actions on a single web element.

b) To find an element using XPath.

c) To find multiple elements with a shared property, such as class name or tag name.

d) To verify that only one element exists with a specific ID.


Answer: c) To find multiple elements with a shared property, such as class name or tag name.


Which method would you use to find the first <div> element on a webpage?


a) driver.findElements(By.tagName("div"));

b) driver.findElement(By.tagName("div"));

c) driver.getElement(By.tagName("div"));

d) driver.getElements(By.tagName("div"));


Answer: b) driver.findElement(By.tagName("div"));


In Selenium, which method does not throw an exception if no elements are found?


a) findElement()

b) findElements()

c) getElement()

d) getElements()


Answer: b) findElements()


If you want to perform a check for the existence of an element and continue without an exception if it is not found, which method should you use?


a) findElement()

b) findElements()

c) checkElement()

d) validateElement()


Answer: b) findElements()


Which method is more suitable for scenarios where multiple elements are expected to be interacted with?


a) findElement()

b) findElements()

c) getSingleElement()

d) checkElements()


Answer: b) findElements()


Which method would you use if you need to verify that a list of web elements exists with a particular attribute?


a) findElement(By.xpath("//element"))

b) findElements(By.xpath("//element"))

c) getElementByAttribute("attribute")

d) getElementsByAttribute("attribute")


Answer: b) findElements(By.xpath("//element"))


What is the behavior of findElement() if the element is not immediately found on the page?


a) It waits until the element becomes available.

b) It returns null.

c) It throws a NoSuchElementException immediately.

d) It waits for a default timeout and then throws an exception.


Answer: d) It waits for a default timeout and then throws an exception.


What type of error handling should you implement when using findElement()?


a) Handle the possible NoSuchElementException with a try-catch block.

b) Implement a loop to retry finding the element.

c) No error handling is necessary.

d) Convert it to a findElements() method call.


Answer: a) Handle the possible NoSuchElementException with a try-catch block.

findElements() in Selenium Java MCQ

 MCQs on Handling Multiple Elements Using findElements() in Selenium Java

What is the return type of the findElements() method in Selenium? 

a) WebElement

b) List<WebElement>

c) ArrayList<WebElement>

d) Set<WebElement>


Answer: b) List<WebElement>


Which of the following is the correct syntax to use the findElements() method to find all buttons on a webpage? 

a) driver.findElements(By.tagName("button"));

b) driver.findElement(By.tagName("button"));

c) driver.getElements(By.tagName("button"));

d) driver.findAll(By.tagName("button"));


Answer: a) driver.findElements(By.tagName("button"));


What will findElements() return if no elements are found matching the locator? 

a) null

b) An empty list

c) An exception

d) A WebElement with null attributes


Answer: b) An empty list


How would you count the number of <div> elements on a webpage using Selenium? 

a) driver.findElement(By.tagName("div")).size();

b) driver.findElements(By.tagName("div")).size();

c) driver.getElements(By.tagName("div")).count();

d) driver.findAll(By.tagName("div")).size();


Answer: b) driver.findElements(By.tagName("div")).size();


Which of the following best describes the difference between findElement() and findElements()? 

a) findElement() returns multiple elements, while findElements() returns a single element.

b) findElement() returns a single element, while findElements() returns a list of elements.

c) Both methods return a single element but differ in exception handling.

d) Both methods return multiple elements but differ in performance.


Answer: b) findElement() returns a single element, while findElements() returns a list of elements.


If you want to iterate through a list of elements returned by findElements(), which Java structure would you typically use? 

a) if statement

b) for or foreach loop

c) switch statement

d) try-catch block


Answer: b) for or foreach loop


What happens when you use findElements() with a locator that matches multiple elements? 

a) It returns only the first matching element.

b) It returns a list containing all matching elements.

c) It throws a NoSuchElementException.

d) It returns the last matching element.


Answer: b) It returns a list containing all matching elements.


Which method would you use to handle multiple elements when you are not sure if all elements will be present on the page? 

a) findElement()

b) findElements()

c) getElements()

d) findAllElements()


Answer: b) findElements()


What exception is thrown by findElements() when no elements are found? 

a) NoSuchElementException

b) ElementNotVisibleException

c) StaleElementReferenceException

d) No exception is thrown; an empty list is returned.


Answer: d) No exception is thrown; an empty list is returned.


How would you print the text of all the elements found using findElements()? 

a) Iterate through the list and use .getText() on each WebElement.

b) Use .printText() on the list directly.

c) Use getText() on the WebDriver instance.

d) Call driver.getText(elements);


Answer: a) Iterate through the list and use .getText() on each WebElement.


If findElements() returns a list with elements, what is the index of the first element? 

a) 1

b) 0

c) -1

d) 2

Answer: b) 0




How can you check if a particular element is part of a list returned by findElements()? 

a) Use the .contains() method on the list.

b) Use the .equals() method on the list.

c) Use the .find() method on the list.

d) Use the .hasElement() method on the list.

Answer: a) Use the .contains() method on the list.


When using findElements() to select elements, which of the following is the best practice to ensure your code does not fail when no elements are found? 

a) Wrap findElements() in a try-catch block.

b) Use an if condition to check if the list is empty before processing it.

c) Always assume that elements will be present.

d) Use findElement() instead of findElements().

Answer: b) Use an if condition to check if the list is empty before processing it.


If findElements() returns a list of size 5, what is the result of calling .get(2) on this list? 

a) The second element in the list.

b) The first element in the list.

c) The third element in the list.

d) An IndexOutOfBoundsException.

Answer: c) The third element in the list.


How do you select all links (anchor tags) on a webpage using findElements()? 

a) driver.findElements(By.tagName("a"));

b) driver.findElements(By.linkText("a"));

c) driver.findElements(By.name("a"));

d) driver.findElements(By.xpath("//a"));

Answer: a) and d  driver.findElements(By.tagName("a"));


If you use findElements() with a By.xpath locator that returns multiple elements, which of the following is true? 

a) The elements are returned in the order they appear in the HTML document.

b) The elements are sorted alphabetically by tag name.

c) The elements are returned in reverse order of appearance in the HTML document.

d) The order of elements is undefined.

Answer: a) The elements are returned in the order they appear in the HTML document.


How can you determine if an element in the list returned by findElements() is displayed on the webpage? 

a) Use .isDisplayed() method on the element.

b) Use .isVisible() method on the element.

c) Use .isShown() method on the element.

d) Use .isPresent() method on the element.

Answer: a) Use .isDisplayed() method on the element.


How can you click on the first element from the list returned by findElements()? 

a) elements.get(0).click();

b) elements.click(0);

c) elements.clickFirst();

d) elements.click();

Answer: a) elements.get(0).click();


If you need to find all elements with a certain tag and attribute combination, which method would you use? 

a) findElement() with a CSS selector

b) findElements() with a CSS selector

c) findElement() with By.xpath

d) findElements() with By.xpath

Answer: b and d) findElements() with By.xpath

CSS Selector Handling Using Selenium Java MCQ

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'

Xpath 2 MCQ


Which of the following XPath expressions would select an element whose id attribute starts with "user"? 

a) //input[contains(@id, 'user')]

b) //input[ends-with(@id, 'user')]

c) //input[starts-with(@id, 'user')]

d) //input[contains(text(), 'user')]


Answer: c) //input[starts-with(@id, 'user')]


How do you select an element using XPath that contains specific text "Login"? 

a) //button[text()='Login']

b) //button[contains(text(), 'Login')]

c) //button[@text='Login']

d) //button[has-text()='Login']


Answer: b) //button[contains(text(), 'Login')]


Which XPath expression would you use to select the last input element in a form? 

a) //input[last()]

b) //input[last()-1]

c) //input[final()]

d) //input[end()]


Answer: a) //input[last()]


How can you select the second input element inside a form using XPath? 

a) //input[2]

b) //input[position()=2]

c) //form/input[2]

d) All of the above


Answer: d) All of the above


What does the XPath expression //* select? 

a) All elements in the document

b) All child elements of the root

c) All elements with an attribute

d) All text nodes


Answer: a) All elements in the document


Which XPath expression will select any element with any attribute? 

a) //*[@*]

b) //*[@]

c) //*[*]

d) //[@*]


Answer: a) //*[@*]


What is the purpose of using the or operator in XPath expressions? 

a) To select elements with multiple attributes

b) To select elements that satisfy at least one of multiple conditions

c) To select elements that do not have a specific attribute

d) To select all child nodes


Answer: b) To select elements that satisfy at least one of multiple conditions


Which XPath expression uses the or operator correctly to select an input element with either id='username' or name='username'? 


a) //input[@id='username' or @name='username']

b) //input[@id='username' || @name='username']

c) //input[id='username' or name='username']

d) //input[@id='username'] | //input[@name='username']


Answer: a) //input[@id='username' or @name='username']


Which XPath expression will select a div that contains an h2 child with the text "Welcome"? 

a) //div[h2='Welcome']

b) //div[h2[text()='Welcome']]

c) //div[contains(h2, 'Welcome')]

d) //div[contains(h2/text(), 'Welcome')]


Answer: b) //div[h2[text()='Welcome']]


Which XPath expression would select any span element that has an id starting with "msg" and also contains the text "error"? 

a) //span[@id='msg' and text()='error']

b) //span[starts-with(@id, 'msg') and contains(text(), 'error')]

c) //span[starts-with(@id, 'msg') or contains(text(), 'error')]

d) //span[@id^='msg' and text*='error']


Answer: b) //span[starts-with(@id, 'msg') and contains(text(), 'error')]


Which XPath expression correctly identifies any child or subchild element with the tag name a? 

a) //a/*

b) //a

c) //*/a

d) //a//*

Answer: d) //a//*


How would you select all input elements that are direct children of a form element? 

a) //form//input

b) //form/input

c) //form[child::input]

d) //form/input/*


Answer: b) //form/input


To find elements where the tag name can be anything but must have a specific attribute, which XPath should be used? a) //*[@attribute='value']

b) //element[@attribute='value']

c) //*[tagname='*' and @attribute='value']

d) //[@attribute='value']

Answer: a) //*[@attribute='value']


What does the XPath expression //*[contains(@class, 'button') and contains(@id, 'submit')] do? 

a) Selects all elements with class button and id containing submit

b) Selects only button elements with id containing submit

c) Selects elements with both class and id containing button and submit respectively

d) Throws an XPath syntax error


Answer: a) Selects all elements with class button and id containing submit


Which of the following XPath expressions correctly uses the position() function? 

a) //div[position() > 1]

b) //div[position()>1]

c) //div[position()>=1]

d) All of the above

Answer: d) All of the above


How would you write an XPath to select any element that has an attribute ending with the value "name"? 

a) //*[@*='name']

b) //*[ends-with(@*, 'name')]

c) //*[@attribute='name']

d) //*[contains(@*, 'name')]

Answer: b) //*[ends-with(@*, 'name')]


Which XPath syntax is used to match all elements with a class attribute of either header or footer? 

a) //*[@class='header' or @class='footer']

b) //*[@class='header' and @class='footer']

c) //[@class='header' | @class='footer']

d) //*[@class*='header,footer']


Answer: a) //*[@class='header' or @class='footer']


What will //button[@type='submit' and @name='login'] select? 

a) All buttons with type='submit' or name='login'

b) All buttons with both type='submit' and name='login' attributes

c) The first button with type='submit'

d) Any element with type='submit' or name='login'


Answer: b) All buttons with both type='submit' and name='login' attributes

XPath Handling Using Selenium Java MCQ

MCQs on XPath Handling Using Selenium Java


What does XPath stand for? 

a) XML Path Language

b) Extensible Path Language

c) X Protocol Language

d) XML Protocol Language


Answer: a) XML Path Language


Which method is used to find an element using XPath in Selenium WebDriver? 

a) driver.findElement(By.xpath())

b) driver.findElement(By.cssSelector())

c) driver.findElement(By.linkText())

d) driver.findElement(By.id())


Answer: a) driver.findElement(By.xpath())


How would you locate an element using an absolute XPath? 

a) driver.findElement(By.xpath("//div[@id='container']/div[1]/input"))

b) driver.findElement(By.xpath("/html/body/div/input"))

c) driver.findElement(By.xpath("//input[@id='username']"))

d) driver.findElement(By.xpath("//button[text()='Submit']"))


Answer: b) driver.findElement(By.xpath("/html/body/div/input"))


What is the difference between an absolute and a relative XPath? 

a) Absolute XPath starts with a "//", while relative XPath starts with "/".

b) Absolute XPath starts with "/", while relative XPath starts with "//".

c) Absolute XPath can contain functions, while relative XPath cannot.

d) Absolute XPath is shorter than relative XPath.


Answer: b) Absolute XPath starts with "/", while relative XPath starts with "//".


Which of the following is a valid relative XPath expression? 

a) /html/body/div/input

b) //div[@class='button']

c) css=input[name='username']

d) .//a[@href='login']


Answer: b) //div[@class='button']


How do you select an element with a specific attribute value using XPath? 

a) driver.findElement(By.xpath("//tagName[@attribute='value']"))

b) driver.findElement(By.xpath("//tagName[attribute='value']"))

c) driver.findElement(By.xpath("//tagName{attribute='value'}"))

d) driver.findElement(By.xpath("//tagName(attribute='value')"))


Answer: a) driver.findElement(By.xpath("//tagName[@attribute='value']"))


Which XPath function is used to select nodes that contain a specific text? 

a) starts-with()

b) contains()

c) ends-with()

d) text()


Answer: b) contains()


How would you locate an element with the text "Submit" using XPath? 

a) driver.findElement(By.xpath("//button[@text='Submit']"))

b) driver.findElement(By.xpath("//button[text()='Submit']"))

c) driver.findElement(By.xpath("//button[.='Submit']"))

d) driver.findElement(By.xpath("//button[@label='Submit']"))


Answer: b) driver.findElement(By.xpath("//button[text()='Submit']"))


What is the purpose of the starts-with() function in XPath? 

a) To select nodes that end with a specific value

b) To select nodes that start with a specific value

c) To select nodes containing a specific text

d) To select nodes with a specific attribute


Answer: b) To select nodes that start with a specific value


How would you select all child elements of a node using XPath? 

a) //parentNode[@child='*']

b) //parentNode/*

c) //parentNode/child::all

d) //parentNode/descendant::*


Answer: b) //parentNode/*


To find an element using multiple conditions with XPath, which operator would you use? 

a) &&

b) OR

c) &&&

d) and

Answer: d) and


How do you locate an element based on its position using XPath? 

a) driver.findElement(By.xpath("//input[position()=2]"))

b) driver.findElement(By.xpath("//input[2]"))

c) driver.findElement(By.xpath("//input[@position='2']"))

d) driver.findElement(By.xpath("//input"))

Answer: a and b


What does the ancestor axis in XPath represent? 

a) Selects all ancestors (parent, grandparent, etc.) of the current node

b) Selects all children of the current node

c) Selects all descendants of the current node

d) Selects the parent of the current node

Answer: a) Selects all ancestors (parent, grandparent, etc.) of the current node


How would you find the last child of an element using XPath? 

a) driver.findElement(By.xpath("//div[last()]"))

b) driver.findElement(By.xpath("//div[@last()]"))

c) driver.findElement(By.xpath("//div[child::last()]"))

d) driver.findElement(By.xpath("//div[@child='last']"))

Answer: a) driver.findElement(By.xpath("//div[last()]"))


To select a node based on a partial match of its attribute using XPath, which function is most appropriate? 

a) starts-with()

b) ends-with()

c) contains()

d) text()

Answer: c) contains()


What is the result of using //div[@*] in an XPath query? 

a) Selects all div elements with an id attribute

b) Selects all div elements with any attribute

c) Selects all div elements without attributes

d) Selects all child elements of div

Answer: b) Selects all div elements with any attribute



How do you select elements that have no children using XPath? 

a) driver.findElement(By.xpath("//element[@empty='true']"))

b) driver.findElement(By.xpath("//element[not(*)]"))

c) driver.findElement(By.xpath("//element[@!child]"))

d) driver.findElement(By.xpath("//element[child::none]"))


Answer: b) driver.findElement(By.xpath("//element[not(*)]"))


Image Handling Using Selenium Java MCQ

 MCQs on Image Handling Using Selenium Java

Which Selenium WebDriver method is used to find an image element by its src attribute? 

a) driver.findElement(By.linkText("src"))

b) driver.findElement(By.tagName("img"))

c) driver.findElement(By.xpath("//img[@src='image.jpg']"))

d) driver.findElement(By.cssSelector("src"))


Answer: c) driver.findElement(By.xpath("//img[@src='image.jpg']"))


How can you retrieve the src attribute of an image element in Selenium WebDriver? 

a) image.getSrc()

b) image.getAttribute("src")

c) image.getText("src")

d) image.getSource()


Answer: b) image.getAttribute("src")


Which of the following methods can be used to verify if an image is displayed on a webpage? 

a) isEnabled()

b) isVisible()

c) isDisplayed()

d) isPresent()


Answer: c) isDisplayed()


To find all images on a webpage, which of the following Selenium commands would you use? 

a) driver.findElements(By.tagName("img"))

b) driver.findElements(By.className("image"))

c) driver.findElements(By.linkText("image"))

d) driver.findElements(By.name("img"))


Answer: a) driver.findElements(By.tagName("img"))


How would you click on an image that is used as a link using Selenium WebDriver? 

a) image.click()

b) driver.findElement(By.cssSelector("img.link")).click()

c) driver.findElement(By.xpath("//a/img")).click()

d) image.sendKeys(Keys.ENTER)


Answer: c) driver.findElement(By.xpath("//a/img")).click()


How can you check if an image is broken (not loaded) using Selenium WebDriver? 

a) By checking if the src attribute is empty

b) By verifying if isDisplayed() returns false

c) By checking if the image size is zero using JavaScript

d) By checking the alt attribute


Answer: c) By checking if the image size is zero using JavaScript


What does the getAttribute("alt") method return when called on an image element? 

a) The source of the image

b) The alternative text of the image

c) The size of the image

d) The title of the image


Answer: b) The alternative text of the image


Which method is used to locate an image by its class name in Selenium WebDriver? 

a) driver.findElement(By.className("imageClass"))

b) driver.findElement(By.id("imageClass"))

c) driver.findElement(By.name("imageClass"))

d) driver.findElement(By.tagName("imageClass"))


Answer: a) driver.findElement(By.className("imageClass"))



How can you get the width and height of an image using Selenium WebDriver? 

a) image.getSize()

b) image.getDimension()

c) image.getSize().getWidth() and image.getSize().getHeight()

d) image.getBounds()


Answer: c) image.getSize().getWidth() and image.getSize().getHeight()



What exception is thrown if an image element is not found on the page? 

a) ElementNotVisibleException

b) NoSuchElementException

c) ElementNotSelectableException

d) TimeoutException

Answer: b) NoSuchElementException



To verify that an image redirects to a new page upon clicking, which sequence of actions is correct? 

a) image.click(); and then driver.getCurrentUrl();

b) image.sendKeys(Keys.ENTER);

c) Actions(driver).doubleClick(image).perform();

d) driver.navigate().to(image.getAttribute("href"));

Answer: a) image.click(); and then driver.getCurrentUrl();


How do you locate an image by using a CSS selector in Selenium WebDriver? 

a) driver.findElement(By.cssSelector("img[src='logo.png']"))

b) driver.findElement(By.linkText("logo.png"))

c) driver.findElement(By.tagName("img[src='logo.png']"))

d) driver.findElement(By.name("img[src='logo.png']"))

Answer: a) driver.findElement(By.cssSelector("img[src='logo.png']"))


Which method is used to validate the tooltip of an image in Selenium WebDriver? 

a) image.getAttribute("tooltip")

b) image.getAttribute("title")

c) image.getTooltip()

d) image.getToolTipText()

Answer: b) image.getAttribute("title")



How do you find an image by its alt text using XPath in Selenium WebDriver? 

a) driver.findElement(By.xpath("//img[@alt='logo']"))

b) driver.findElement(By.xpath("//img[text()='logo']"))

c) driver.findElement(By.xpath("//img[@name='logo']"))

d) driver.findElement(By.xpath("//img[@title='logo']"))

Answer: a) driver.findElement(By.xpath("//img[@alt='logo']"))

Button Handling Using Selenium Java MCQ

 MCQs on Button Handling Using Selenium Java

Which Selenium WebDriver method is used to click a button? 

a) submit()

b) click()

c) navigate()

d) select()


Answer: b) click()


How do you locate a button using its ID in Selenium WebDriver? 

a) driver.findElement(By.name("buttonID"))

b) driver.findElement(By.className("buttonID"))

c) driver.findElement(By.id("buttonID"))

d) driver.findElement(By.tagName("buttonID"))


Answer: c) driver.findElement(By.id("buttonID"))


Which of the following methods checks whether a button is displayed on the webpage? 

a) isVisible()

b) isDisplayed()

c) isEnabled()

d) isSelected()


Answer: b) isDisplayed()


How can you determine if a button is enabled or disabled using Selenium WebDriver? 

a) isEnabled()

b) isVisible()

c) isDisplayed()

d) isClickable()


Answer: a) isEnabled()


Which method is used to retrieve the text of a button in Selenium WebDriver? 

a) getText()

b) getAttribute("value")

c) getAttribute("text")

d) getButtonText()


Answer: a) getText()


How do you click a button using its class name in Selenium WebDriver? 

a) driver.findElement(By.className("buttonClass")).click();

b) driver.findElement(By.id("buttonClass")).click();

c) driver.findElement(By.name("buttonClass")).click();

d) driver.findElement(By.tagName("buttonClass")).click();


Answer: a) driver.findElement(By.className("buttonClass")).click();


Which of the following Selenium commands will simulate clicking a button using its XPath? 

a) driver.findElement(By.name("//button[text()='Submit']")).click();

b) driver.findElement(By.xpath("//button[text()='Submit']")).click();

c) driver.findElement(By.cssSelector("//button[text()='Submit']")).click();

d) driver.findElement(By.linkText("//button[text()='Submit']")).click();


Answer: b) driver.findElement(By.xpath("//button[text()='Submit']")).click();


What will happen if you attempt to click a disabled button using Selenium WebDriver? 

a) It will click the button without any issue.

b) It will throw an ElementNotInteractableException.

c) It will throw a NoSuchElementException.

d) It will submit the form.


Answer: b) It will throw an ElementNotInteractableException.


To retrieve the value of a button's attribute, which method would you use? 

a) getText("attributeName")

b) getValue("attributeName")

c) getAttribute("attributeName")

d) getProperty("attributeName")

Answer: c) getAttribute("attributeName")



Which of the following methods is used to click a button with a specific tag name? 

a) driver.findElement(By.tagName("button")).click();

b) driver.findElement(By.name("button")).click();

c) driver.findElement(By.className("button")).click();

d) driver.findElement(By.linkText("button")).click();

Answer: a) driver.findElement(By.tagName("button")).click();



What will getCssValue("background-color") return when called on a button element? 

a) The text of the button

b) The value of the "background-color" CSS property

c) The HTML of the button

d) The ID of the button

Answer: b) The value of the "background-color" CSS property


Which of the following statements correctly retrieves the tooltip of a button? 

a) button.getTooltip();

b) button.getAttribute("tooltip");

c) button.getAttribute("title");

d) button.getTooltipText();

Answer: c) button.getAttribute("title");



What is the purpose of the submit() method when used with a button element in Selenium? 

a) To click the button

b) To simulate pressing the ENTER key

c) To submit the form containing the button

d) To clear the button's text

Answer: c) To submit the form containing the button


How would you find all buttons with the class name "btn-primary"? 

a) driver.findElements(By.className("btn-primary"))

b) driver.findElements(By.id("btn-primary"))

c) driver.findElements(By.tagName("button-primary"))

d) driver.findElements(By.name("btn-primary"))

Answer: a) driver.findElements(By.className("btn-primary"))


To click a button with a dynamic ID that changes every time the page is loaded, which locator strategy is most reliable? 

a) By.id()

b) By.name()

c) By.xpath()

d) By.cssSelector()

Answer: c) By.xpath()

Links Handling Using Selenium Java MCQ

 MCQs on Links Handling Using Selenium Java

Which Selenium WebDriver method is used to click on a link? 

a) submit()

b) navigate()

c) click()

d) select()


Answer: c) click()


How do you locate a link using its text in Selenium WebDriver? 

a) driver.findElement(By.linkText("Click Here"))

b) driver.findElement(By.text("Click Here"))

c) driver.findElement(By.name("Click Here"))

d) driver.findElement(By.id("Click Here"))


Answer: b) driver.findElement(By.text("Click Here"))


Which method is used to locate a link containing a specific substring of its text? 

a) By.partialLinkText()

b) By.subLinkText()

c) By.linkText()

d) By.partialText()


Answer: a) By.partialLinkText()


What does the getAttribute("href") method return when called on a link element? 

a) The text of the link

b) The URL that the link points to

c) The title attribute of the link

d) The ID of the link


Answer: b) The URL that the link points to



Which of the following locator strategies is used to find a link by its partial text? 

a) By.linkText()

b) By.partialLinkText()

c) By.xpath()

d) By.cssSelector()


Answer: b) By.partialLinkText()


How would you verify if a link is displayed on a webpage using Selenium WebDriver? 

a) isEnabled()

b) isVisible()

c) isDisplayed()

d) isClickable()


Answer: c) isDisplayed()


What exception is thrown if a link element is not found on the page? 

a) ElementNotVisibleException

b) NoSuchElementException

c) ElementNotSelectableException

d) TimeoutException


Answer: b) NoSuchElementException


Which Selenium WebDriver method is used to get the text of a link? 

a) getAttribute("text")

b) getText()

c) getLinkText()

d) getTextValue()


Answer: b) getText()



Which method can be used to navigate to a URL specified in the href attribute of a link? 

a) driver.get(link.getAttribute("href"));

b) driver.navigate().to(link.getAttribute("href"));

c) driver.go(link.getAttribute("href"));

d) Both a) and b)

Answer: d) Both a) and b)


What is the purpose of using driver.findElements(By.tagName("a")) in Selenium? 

a) To find all the buttons on the webpage

b) To find all the links on the webpage

c) To find all the input elements on the webpage

d) To find all the form elements on the webpage

Answer: b) To find all the links on the webpage


Which of the following locators would you use to find a link with the exact text "Home"? 

a) By.name("Home")

b) By.className("Home")

c) By.linkText("Home")

d) By.partialLinkText("Home")

Answer: c) By.linkText("Home")


If a link contains dynamic text that changes frequently, which locator strategy is the most reliable? 

a) By.id()

b) By.linkText()

c) By.partialLinkText()

d) By.className()

Answer: c) By.partialLinkText()



How would you check if a link is enabled for clicking in Selenium WebDriver? 

a) isEnabled()

b) isClickable()

c) isDisplayed()

d) isSelectable()

Answer: a) isEnabled()


What is the best way to locate a link that contains the word "Download" anywhere in its text? 

a) By.linkText("Download")

b) By.partialLinkText("Download")

c) By.cssSelector("a[href*='Download']")

d) By.xpath("//a[contains(text(),'Download')]")

Answer: b, d) By.xpath("//a[contains(text(),'Download')]")


What will happen if you try to click a link that is not visible on the screen? 

a) It will scroll to the link and click it.

b) It will throw an ElementNotInteractableException.

c) It will throw a NoSuchElementException.

d) It will click the link without any issue.

Answer: b) It will throw an ElementNotInteractableException.



Checkbox Handling Using Selenium Java MCQ

 MCQs on Checkbox Handling Using Selenium Java

Which Selenium WebDriver method is used to select a checkbox? 

a) check()

b) click()

c) select()

d) choose()


Answer: b) click()


How do you verify if a checkbox is selected in Selenium WebDriver? 

a) isSelected()

b) isChecked()

c) isEnabled()

d) isVisible()


Answer: a) isSelected()


Which method would you use to ensure that a checkbox is displayed on the webpage? 

a) isVisible()

b) isDisplayed()

c) isEnabled()

d) isPresent()


Answer: b) isDisplayed()


How can you select a checkbox using its ID attribute in Selenium WebDriver? 

a) driver.findElement(By.id("checkbox1")).click();

b) driver.findElement(By.name("checkbox1")).click();

c) driver.findElement(By.className("checkbox1")).click();

d) driver.findElement(By.tagName("checkbox")).click();


Answer: a) driver.findElement(By.id("checkbox1")).click();


Which exception is thrown if a checkbox element is not found on the page? 

a) ElementNotVisibleException

b) NoSuchElementException

c) ElementNotSelectableException

d) TimeoutException


Answer: b) NoSuchElementException


How would you locate a checkbox using its name attribute and select it? 

a) driver.findElement(By.name("remember")).click();

b) driver.findElement(By.id("remember")).click();

c) driver.findElement(By.className("remember")).click();

d) driver.findElement(By.xpath("//input[@name='remember']")).click();


Answer: a) driver.findElement(By.name("remember")).click();


If a checkbox is selected by default, how can you deselect it using Selenium WebDriver? 

a) click()

b) deselect()

c) uncheck()

d) select(false)


Answer: a) click()





What happens when you try to click on a disabled checkbox in Selenium? 

a) It selects the checkbox without any error.

b) It throws ElementNotInteractableException.

c) It throws NoSuchElementException.

d) It throws InvalidElementStateException.


Answer: d) It throws InvalidElementStateException.


Which method would you use to check if a checkbox is enabled? 

a) isEnabled()

b) isSelected()

c) isVisible()

d) isDisplayed()

Answer: a) isEnabled()


Which of the following will ensure a checkbox is not selected before performing an action? 

a) if (!checkbox.isEnabled()) { checkbox.click(); }

b) if (!checkbox.isSelected()) { checkbox.click(); }

c) if (checkbox.isDisplayed()) { checkbox.click(); }

d) if (checkbox.isVisible()) { checkbox.click(); }

Answer: b) if (!checkbox.isSelected()) { checkbox.click(); }



What will getAttribute("checked") return when a checkbox is selected? 

a) "true"

b) "checked"

c) null

d) "selected"

Answer: b) "checked"


To select a checkbox using CSS Selector, which of the following is correct? 

a) driver.findElement(By.cssSelector("input[name='subscribe']")).click();

b) driver.findElement(By.cssSelector("checkbox[name='subscribe']")).click();

c) driver.findElement(By.cssSelector("div[name='subscribe']")).click();

d) driver.findElement(By.cssSelector("span[name='subscribe']")).click();

Answer: a) driver.findElement(By.cssSelector("input[name='subscribe']")).click();


What will happen if you try to retrieve the text of a checkbox label using getText()? 

a) Returns "true" or "false"

b) Returns the checkbox state (checked or unchecked)

c) Returns the text label associated with the checkbox

d) Throws an exception

Answer: c) Returns the text label associated with the checkbox


Which of the following statements will find and click on the first checkbox in a list of checkboxes? 

a) driver.findElements(By.name("check")).get(0).click();

b) driver.findElements(By.id("check")).get(0).click();

c) driver.findElements(By.className("check")).get(0).click();

d) driver.findElements(By.tagName("check")).get(0).click();

Answer: a) driver.findElements(By.name("check")).get(0).click();


To clear a checkbox that is already selected, which method is used? 

a) clear()

b) uncheck()

c) click()

d) deselect()

Answer: c) click()


How can you ensure a specific checkbox is selected among multiple checkboxes with the same name attribute? 

a) Use findElements and iterate through all checkboxes.

b) Use findElement with By.name and click on it directly.

c) Use By.className to find the correct checkbox.

d) Use By.id to find the correct checkbox.

Answer: a) Use findElements and iterate through all checkboxes.

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...