Saturday, August 24, 2024

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

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