MCQs on Handling Auto-Suggestion Using Selenium Java
Which Selenium WebDriver method is commonly used to send text to a search box to trigger auto-suggestions?
a) sendText("text")
b) sendKeys("text")
c) setInput("text")
d) type("text")
Answer: b) sendKeys("text")
To capture all auto-suggestions displayed in a drop-down, which Selenium method is most appropriate?
a) findElement(By.name("suggestions"))
b) findElement(By.className("suggestions"))
c) findElements(By.xpath("//ul[@role='listbox']//li"))
d) findElement(By.cssSelector("div.suggestions"))
Answer: c) findElements(By.xpath("//ul[@role='listbox']//li"))
How do you select an auto-suggestion from the list that matches a specific text using Selenium?
a) Use element.selectByText("suggestion")
b) Use a loop with getText() and click()
c) Use driver.selectOptionByText("suggestion")
d) Use driver.pick("suggestion")
Answer: b) Use a loop with getText() and click()
Which method is used to simulate typing in a text box to trigger auto-suggestions?
a) element.inputText("query")
b) element.type("query")
c) element.sendKeys("query")
d) element.enterText("query")
Answer: c) element.sendKeys("query")
What is the purpose of using Thread.sleep() when handling auto-suggestions in Selenium?
a) To stop the browser
b) To wait for the suggestions to appear
c) To close the auto-suggestion list
d) To refresh the page
Answer: b) To wait for the suggestions to appear
In a scenario where you need to handle dynamic auto-suggestions, what is the best practice?
a) Use hard-coded wait times
b) Use WebDriverWait with ExpectedConditions
c) Refresh the page frequently
d) Use static waits
Answer: b) Use WebDriverWait with ExpectedConditions
When handling auto-suggestions, what Selenium method is best for scrolling to a specific suggestion in the list?
a) scrollToElement()
b) Actions.moveToElement(element).build().perform()
c) scrollIntoView()
d) scrollDownTo()
Answer: b) Actions.moveToElement(element).build().perform()
To avoid StaleElementReferenceException while handling auto-suggestions, what approach should be followed?
a) Refresh the page and retry
b) Store the elements in a list and use them directly
c) Always re-fetch elements after triggering the suggestion
d) Increase the timeout
Answer: c) Always re-fetch elements after triggering the suggestion
How can you verify the total number of auto-suggestions displayed after entering text in a search box?
a) element.countSuggestions()
b) driver.findElements(By.xpath("//ul[@role='listbox']//li")).size()
c) driver.getSuggestionsCount()
d) driver.findElements(By.className("suggestion")).size()
Answer: b) driver.findElements(By.xpath("//ul[@role='listbox']//li")).size()
Which ExpectedConditions is used to ensure that auto-suggestions are visible before interacting with them?
a) visibilityOfElementLocated(By.xpath(...))
b) presenceOfElementLocated(By.xpath(...))
c) elementToBeClickable(By.xpath(...))
d) textToBePresentInElement(By.xpath(...))
Answer: a) visibilityOfElementLocated(By.xpath(...))
What is the Selenium strategy to interact with a dynamic list of auto-suggestions?
a) Use index-based clicks
b) Use the text-based search and click method
c) Use selectByVisibleText()
d) Use JavaScript to select the element
Answer: b) Use the text-based search and click method
Which approach is most reliable for dealing with rapidly changing auto-suggestions?
a) Use Thread.sleep() generously
b) Use FluentWait to handle dynamic waits
c) Use only CSS selectors
d) Increase the timeout to a very high value
Answer: b) Use FluentWait to handle dynamic waits
Which Selenium class is most useful for automating actions such as typing and selecting auto-suggestions?
a) Actions
b) JavascriptExecutor
c) Select
d) WebDriver
Answer: a) Actions
If the auto-suggestion list is not clickable, what is a good workaround in Selenium?
a) Use JavaScript to perform a click
b) Use sendKeys(Keys.ENTER) to select the first suggestion
c) Refresh the page and retry
d) Use driver.clickOnInvisibleElement()
Answer: a) Use JavaScript to perform a click
When selecting a specific auto-suggestion based on visible text, which Selenium WebDriver approach is most effective?
a) Iterate through the list and match text with getText()
b) Use driver.findElement(By.visibleText())
c) Use driver.clickElementByText()
d) Use selectOption("text")
Answer: a) Iterate through the list and match text with getText()
Which command is used to press the down arrow key to navigate through auto-suggestions?
a) element.sendKeys(Keys.DOWN)
b) element.press(Keys.ARROW_DOWN)
c) element.arrowDown()
d) element.sendKey(Keys.ARROW_DOWN)
Answer: a) element.sendKeys(Keys.DOWN)
What is the advantage of using FluentWait over WebDriverWait when handling dynamic auto-suggestions?
a) FluentWait allows for more frequent polling intervals and custom exception handling
b) FluentWait has a longer default timeout
c) FluentWait can refresh the page automatically
d) FluentWait ignores all exceptions
Answer: a) FluentWait allows for more frequent polling intervals and custom exception handling
In Selenium, how would you dynamically select an auto-suggestion using partial text matching?
a) driver.findElement(By.partialLinkText("suggestion"))
b) Loop through elements and use getText().contains("text")
c) driver.findElement(By.textContains("text"))
d) driver.partialText("text")
Answer: b) Loop through elements and use getText().contains("text")
When auto-suggestions are loaded dynamically via AJAX, what must you ensure before attempting to interact with them?
a) All suggestions have fully loaded and are visible
b) The page is refreshed
c) The input field is cleared
d) A screenshot is taken
Answer: a) All suggestions have fully loaded and are visible
No comments:
Post a Comment