
Q31
Q31 What is the purpose of locators in Selenium WebDriver?
To locate elements on a web page
To execute JavaScript
To handle browser cookies
To switch between windows
Q32
Q32 Which of the following is NOT a valid locator in Selenium WebDriver?
ID
Name
FilePath
XPath
Q33
Q33 What does the By.cssSelector() method do in Selenium?
Finds elements by ID
Finds elements by CSS
Finds elements by class
Finds elements by XPath
Q34
Q34 Why is the ID locator considered the fastest and most reliable in Selenium?
It is unique to each page element
It is the default locator
It uses advanced algorithms
It supports dynamic elements
Q35
Q35 Which locator strategy is the most suitable for elements without unique IDs or names?
CSS Selector
XPath
Class
TagName
Q36
Q36 What is the primary difference between absolute and relative XPath?
Absolute uses "//"; relative uses "../"
Absolute starts from the root; relative starts from any node
Absolute is faster
Relative only works with IDs
Q37
Q37 Write a command to locate an element by its name attribute in Selenium WebDriver.
driver.findElement(By.name("attribute"))
driver.findElement(By.id("attribute"))
driver.findElement(By.xpath("attribute"))
driver.findElement(By.tagName("attribute"))
Q38
Q38 How do you click on a link using its partial text in Selenium WebDriver?
driver.findElement(By.partialLinkText("text")).click()
driver.findElement(By.tagName("text")).click()
driver.findElement(By.linkText("text")).click()
driver.findElement(By.xpath("text")).click()
Q39
Q39 Write an XPath expression to locate the third child element of a div with class "example".
//div[@class="example"]/child[3]
//div[@class="example"]/*[3]
//div[@class="example"]/3
//div[3][@class="example"]
Q40
Q40 A Selenium test fails to find an element using the Name locator. What could be the reason?
Name is not unique
Incorrect locator
Element is not interactable
Name is case-sensitive
Q41
Q41 A test script throws an "InvalidSelectorException." What is the likely issue?
Invalid XPath
Incorrect element ID
Unsupported browser
Locator strategy is outdated
Q42
Q42 Why might a "StaleElementReferenceException" occur during a Selenium test?
The element is no longer present in the DOM
The element has a dynamic attribute
The browser driver crashed
The page was reloaded
Q43
Q43 What is a primary benefit of using a test automation framework?
Reduces execution time
Improves test structure and reusability
Eliminates manual testing
Provides better debugging tools
Q44
Q44 Which of the following is NOT a common type of test automation framework?
Modular
Data-driven
Keyword-driven
Requirement-driven
Q45
Q45 What is the key characteristic of a modular test automation framework?
Tests are organized into independent modules
Tests are hardcoded
No parameterization
Framework lacks scalability
Q46
Q46 Why is a data-driven framework advantageous?
Reduces coding complexity
Allows reusability of test data
Simplifies debugging
Facilitates dynamic test cases
Q47
Q47 In a keyword-driven framework, what defines test execution steps?
Hardcoded scripts
External files with keywords
Inline data
Database tables
Q48
Q48 What is the primary challenge in implementing a hybrid framework?
Combining different framework features
Integrating tools
Managing data files
Handling cross-browser testing
Q49
Q49 Write a command to set a global timeout in Selenium WebDriver.
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.setTimeout(10);
driver.timeout(10);
driver.globalTimeout(10);
Q50
Q50 How do you parameterize a test in TestNG using a DataProvider?
@DataProvider(name="data")
@Test(dataProvider="data")
@TestProvider("data")
@Provider("data")
Q51
Q51 Write a script snippet to handle a dynamic web table in Selenium WebDriver.
driver.findElement(By.tagName("table"));
driver.findElement(By.xpath("//table/tr/td"));
driver.findElement(By.cssSelector("table td"));
driver.findElement(By.xpath("//table//td[text()='Dynamic']"));
Q52
Q52 Why might a test fail when using a data-driven framework?
Incorrect test script
Missing test data file
Invalid data format
All of these
Q53
Q53 A hybrid framework throws an error during execution. What could be the issue?
Improper tool integration
Data parsing error
Incorrect file path
Unsupported browser
Q54
Q54 Why might a "FrameworkInitializationException" occur?
Incorrect configuration
Duplicate test cases
Timeout issues
Invalid test data
Q55
Q55 What is the purpose of TestNG in test automation?
To perform UI testing
To create test reports
To organize and execute test cases
To replace Selenium
Q56
Q56 Which annotation in TestNG is used to define a method that runs only once before all tests?
@BeforeTest
@BeforeSuite
@BeforeClass
@BeforeMethod
Q57
Q57 What is the role of the @DataProvider annotation in TestNG?
To provide test data
To initialize test setup
To execute test scripts
To generate test reports
Q58
Q58 How does JUnit identify a test method?
Using the @Before annotation
Using the @Test annotation
Using the @Run annotation
Using the @Suite annotation
Q59
Q59 What is the primary difference between TestNG and JUnit?
TestNG supports parallel testing
JUnit supports multiple reports
TestNG lacks data-driven testing
JUnit lacks annotations for setup
Q60
Q60 Write a TestNG annotation to skip a test method conditionally.
@Skip
@Ignore
@Conditional
@Test(enabled=false)