Enhance your Selenium automation skills with these 30 MCQs on web table handling. Learn to identify rows and columns, fetch data from dynamic tables, and manage pagination effectively.
Handling Web Tables in Selenium – MCQs
1. Identifying Table Rows and Columns (10 Questions)
Which Selenium method retrieves all rows of a table? a) findElements(By.tagName("row")) b) findElements(By.tagName("tr")) c) findElements(By.className("rows")) d) findElements(By.xpath("//table/row"))
How can you locate all columns in a specific row of a table? a) findElements(By.cssSelector("td")) b) findElements(By.tagName("td")) c) findElements(By.className("columns")) d) findElements(By.xpath("//row/column"))
What locator is best for finding a cell in the second row and third column of a table? a) By.xpath("//table/tr[2]/td[3]") b) By.cssSelector("tr:nth-child(2) td:nth-child(3)") c) Both a and b d) None of the above
Which of the following is the correct XPath to retrieve all rows of a table? a) //table/tr b) //table/rows c) //table/allRows d) //tr
How do you count the total number of rows in a table? a) findElement(By.xpath("//table/tr")).size() b) findElements(By.xpath("//table/tr")).size() c) findElements(By.cssSelector("table tr")).count() d) getRowCount()
What is the purpose of findElements() in Selenium when working with tables? a) To retrieve all matching elements b) To retrieve a single element c) To highlight table elements d) To clear table data
Which locator is most reliable for identifying a specific cell in a table? a) By.className b) By.xpath c) By.id d) By.name
What will findElement(By.xpath("//tr[3]")) return? a) The third table b) The third row of a table c) The third column of a row d) The entire table
How do you locate a table by its class name? a) By.className b) By.xpath("//table[@class='classname']") c) Both a and b d) By.name
Which of the following is a valid way to access table headers? a) findElements(By.tagName("th")) b) findElements(By.cssSelector("th")) c) Both a and b d) findElements(By.className("tableHeader"))
2. Fetching Data from Dynamic Tables (10 Questions)
What approach is used to retrieve data from dynamic web tables? a) Static locators b) Dynamic XPath or CSS Selectors c) Hardcoded values d) Browser plugins
How can you iterate through all rows in a dynamic table? a) Use a for loop with findElements(By.xpath("//tr")) b) Use findElement(By.xpath("//table")) c) Use getRows() method d) Selenium cannot handle dynamic tables
What method in Selenium retrieves text from a table cell? a) getText() b) fetchText() c) readCell() d) extractData()
Which locator can be used to find a table cell containing specific text? a) By.xpath("//td[contains(text(), 'value')]") b) By.cssSelector("td[text='value']") c) Both a and b d) By.className("cellValue")
How do you ensure that your XPath works for tables with dynamic IDs? a) Use contains() or starts-with() in XPath b) Use static locators c) Use findById() d) Selenium cannot handle dynamic IDs
What is the best way to handle tables where rows appear dynamically upon scrolling? a) Scroll using JavaScriptExecutor b) Use Action class for scrolling c) Both a and b d) Reload the page
How can you identify a row based on a unique value in one of its columns? a) By.xpath("//tr[td[text()='uniqueValue']]") b) By.cssSelector("tr[value='uniqueValue']") c) Both a and b d) By.className("rowIdentifier")
How do you retrieve the total number of columns in a dynamic table? a) findElements(By.xpath("//tr[1]/td")).size() b) findElements(By.xpath("//table/thead/tr/th")).size() c) Both a and b d) getColumnCount()
Which method handles data dynamically updated via JavaScript? a) WebDriverWait with ExpectedConditions b) Thread.sleep() c) reloadPage() d) findDynamic()
What is the purpose of ExpectedConditions.visibilityOfElementLocated() in dynamic tables? a) To wait until a table element is visible b) To highlight table elements c) To scroll to a specific row d) To count table rows
3. Handling Pagination (10 Questions)
What is the primary challenge with handling pagination in Selenium? a) Identifying clickable elements for next pages b) Locating dynamic rows c) Synchronizing scrolls d) Working with JavaScript
Which method retrieves the text of a pagination button? a) getText() b) readPaginationText() c) fetchButton() d) getPaginationValue()
How do you move to the next page in a paginated table? a) Click the “Next” button using findElement(By.xpath("//button[text()='Next']")) b) Use scrollToNextPage() c) Use navigateNext() d) Reload the page
Which Selenium strategy is best for looping through all pages of a paginated table? a) Use a while loop until the “Next” button is disabled b) Use recursion c) Use JavaScriptExecutor d) Selenium cannot handle pagination
How do you identify the “Next” button in a pagination bar? a) By.xpath("//button[contains(text(), 'Next')]") b) By.cssSelector(".nextButton") c) Both a and b d) By.id("next")
How can you ensure Selenium handles pagination dynamically? a) Use WebDriverWait to wait for the next page to load b) Use Thread.sleep() after clicking the “Next” button c) Both a and b d) Use navigateToNextPage()
How do you fetch data from all pages of a paginated table? a) Iterate through pages using “Next” and retrieve data from each b) Use getAllData() c) Paginated tables cannot be handled by Selenium d) Load all data at once
What condition is checked to determine if pagination is complete? a) If the “Next” button is disabled b) If all rows are visible c) If the last page number is reached d) If table scrolling stops
What should you do if the pagination elements are inside an iframe? a) Switch to the iframe using switchTo().frame() b) Use scrollToIframe() c) Locate the iframe and click elements inside it d) Reload the page
How can you capture all data from a dynamically paginated table? a) Combine data from all pages in a loop b) Use getAllRows() c) Use mergeAllData() d) Selenium cannot capture all data
Handling Web Tables in Selenium:
Qno
Answer
1
b) findElements(By.tagName(“tr”))
2
b) findElements(By.tagName(“td”))
3
c) Both a and b
4
a) //table/tr
5
b) findElements(By.xpath(“//table/tr”)).size()
6
a) To retrieve all matching elements
7
b) By.xpath
8
b) The third row of a table
9
b) By.xpath(“//table[@class=’classname’]”)
10
c) Both a and b
11
b) Dynamic XPath or CSS Selectors
12
a) Use a for loop with findElements(By.xpath("//tr"))
13
a) getText()
14
a) By.xpath(“//td[contains(text(), ‘value’)]”)
15
a) Use contains() or starts-with() in XPath
16
c) Both a and b
17
a) By.xpath("//tr[td[text()='uniqueValue']]")
18
c) Both a and b
19
a) WebDriverWait with ExpectedConditions
20
a) To wait until a table element is visible
21
a) Identifying clickable elements for next pages
22
a) getText()
23
a) Click the “Next” button using findElement(By.xpath("//button[text()='Next']"))
24
a) Use a while loop until the “Next” button is disabled
25
c) Both a and b
26
a) Use WebDriverWait to wait for the next page to load
27
a) Iterate through pages using “Next” and retrieve data from each