1/6 By Varsha July 2, 2021 Latest Selenium Interview Questions And Answers automationqahub.com/latest-selenium-interview-questions-and-answers/ 1)What is the difference between selenium 3 and selenium 4. Selenium 3 uses the JSON wire protocol and selenium 4 uses W3C standardization.  Native Support was removed for browsers like Opera and PhantomJs in selenium 4. Selenium IDE was only available as a Firefox extension in version 3. However, in selenium version 4 IDE is available for Chrome as well. Unlike selenium 3, Selenium 4 provides native support for chrome DevTools. Selenium 4 has introduced Relative locators that allow testers to find elements relative to another element in DOM. Docker support has been added to the Grid server for more efficient parallel execution. 2) Which selenium web driver locator should be preferred? ID is the preferred choice because it is less prone to changes, However, CSS is considered to be faster and is usually easy to read. XPath can walk up and down the DOM, which makes Xpath more customizable. 3)Explain difference between findElement() and find elements(). findElement(): This command is used for finding a particular element on a web page, it is used to return an object of the first found element by the locator. Throws NoSuchElementException if the element is not found. find elements(): This command is used for finding all the elements in a web page specified by the locator value. The return type of this command is the list of all the matching web elements. It returns an empty list if no matching element is found. 4)Explain the difference between Thread.Sleep() and selenium.setSpeed(). Thread.Sleep(): It causes the current thread to suspend execution for a specified period. selenium.setSpeed():setSpeed sets a speed that will apply a delay time before every Selenium operation. 5)How to handle stale element reference exception? The stale element exception occurs when the element is destroyed and recreated again in DOM. When this happens the reference of the element in DOM becomes stale. This can be handled in numerous ways.
2/6 1)Refresh the page and try to locate the stale element again. 2) Use Explicit wait to ignore the stale element exception. 3) Try to access the element several times in the loop(Usually not recommended.) 6)How many types of WebDriver APIs are available in selenium. Chrome, Geko Driver, Chromium, Edge. 7)How to open the browser in incognito mode. This can be done by using ChromeOptions class to customize the chrome driver session and adding the argument as “incognito”. ChromeOptions options = new ChromeOptions(); options.addArguments(“– incognito”); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); 8)How to handle file upload in selenium. File upload can be done in 3 ways: By using Robot class. By using sendkeys. By using AutoIt. 9)How many parameters are selenium required? Selenium requires four parameters: Host Port Number Browser URL 10)How to retrieve css properties of an element. driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”); driver.findElement(By.id(“id“)).getCssValue(“font-size”);  11)How can you use the Recovery Scenario in Selenium WebDriver? By using “Try Catch Block” within Selenium WebDriver Java tests. 12)How To Highlight Element Using Selenium WebDriver? Use Javascript Executor interface: JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("arguments[0].setAttribute('style', 'background: yellow; border: 2px solid red;');", element);
3/6 13)Explain a few advantages of the Page Object Model. Readable and Maintainable code. Less and optimized code. Low redundancy. 14)List some Commonly used interfaces of selenium web driver. WebDriver TakesScreenshot JavascriptExecutor WebElement SearchContext 15)What is the difference between @FindAll and @Findbys. @FindBys: When the required WebElement objects need to match all of the given criteria use @FindBys annotation. @FindBys( { @FindBy(className = "class1") @FindBy(className = "class2") } ) private List<WebElement> ele //elements With Both_class1 AND class2; @FindAll: When required WebElement objects need to match at least one of the given criteria use the @FindAll annotation. @FindAll({ @FindBy(className = "class1") @FindBy(className = "class2") }) private List<WebElement> ele //elements With Either_class1 OR class2 ; 16)How to Click on a web element if the selenium click() command is not working. There are multiple ways provided by the selenium web driver to perform click operations. You can use either Action class or can leverage javascript executor. a) Javascript executor is an interface provided by selenium to run javascript through selenium web driver. import org.openqa.selenium.JavascriptExecutor; public void clickThruJS(WebElement element) { JavascriptExecutor executor = (JavascriptExecutor) Driver; executor.executeScript(“arguments[0].click();”, element); }
4/6 b) Action class is provided by selenium to handle mouse and keyboard interactions. import org.openqa.selenium.interactions.Actions; public void ClickToElement(WebElement elementName) { Actions actions = new Actions(Driver); actions.moveToElement(elementName).perform(); actions.moveToElement(elementName).click().perform(); } 17)How to exclude a test method from execution in TestNG. By adding the exclude tag in the testng.xml file. <classes> <class name=”TestCaseName”> <methods> <exclude name=”TestMethodName”/> </methods> </class> </classes> 18)What are different ways of ignoring a test from execution. Making parameter “enabled” as “false”. Using the “exclude” parameter in testng.xml. “throw new SkipException()” in the if condition to Skip / Ignore Test. 19)What is the difference between scenario and scenario outline in cucumber? When we want to execute a test one time then we use the scenario keyword. If we want to execute a test multiple times with different sets of data then we use the scenario outline keyword. A scenario outline is used for data-driven testing or parametrization. We use example keywords to provide data to the scenario outline 20)What are different ways to reload a webpage in selenium? 1)Driver.navigate().refresh() 2)Driver.get(Driver.getCurrentUrl()) 3)Driver. findElement(By.id(“id”)).sendKeys(Keys.F5); 4)Driver.navigate().to(Driver.getCurrentUrl()) 21)What is the difference between getText() and getAttribute(). getText() method returns the text present which is visible on the page by ignoring the leading and trailing spaces, while the getAttribute() method returns the value of the attribute defined in the HTML tag. 22)How to disable Chrome notifications using selenium? You need to use chrome options to disable notifications on chrome:
5/6 Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("profile.default_content_setting_values.notifications", 2); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", prefs); WebDriver driver = new ChromeDriver(options); 23)What is the difference between @BeforeTest and @BeforeMethod? @BeforeTest will run only once before each test tag defined in testng.xml, however, @BeforeMethod will run before every method annotated with the @Test tag. In other words, every test in a file is a method but vice versa is not true, so no matter how many methods are annotated with @Test, @BeforeTest will be called only one time and @BeforeMethod executes before each test method. 24)Explain cucumberOptions with the keywords. @CucumberOptions enables us to define some settings for our tests, it works like the cucumber JVM command line. Using @CucumberOptions we can define the path of the feature file and the step definition file, we can also use other keywords to set our test execution properly. 25)What is cucumber DryRun? Dry Run is used to check the complete implementation of all the mentioned steps present in the Feature file. If it is set as true, then Cucumber will check that every Step mentioned in the Feature File has corresponding code written in the Step Definition file or not. 26)How to set the Priority of cucumber Hooks? @Before(order = int) : This runs in incremental order, like (order=0) will execute first then (order=1) and so on. @After(order = int): This executes in decremental order, which means value 1 would run first and 0 would be after 1. 27)What is a data table in cucumber and how to use it? Data tables are used when the scenario step requires to be tested with multiple input parameters, multiple rows of data can be passed in the same step and it’s much easier to read. Scenario: Valid Registration Form Information Given User submits a valid registration form | John | Doe |01-01-1990 |999999999 | Then System proceeds with registration 28)Explain invocation count in testNg.
6/6 invocation count: It refers to the number of times a method should be invoked. It will work as a loop. Eg: @Test(invocation count = 7) . Hence, this method will execute 7 times. 29)Explain build().perform() in actions class. build()  This method in the Actions class is used to create a chain of action or operation you want to perform. perform()  This method is used toexecute a chain of actions that are built using the Action build method. 30)What is the difference between driver.close() and driver.quit()? driver. close(): Close the browser window which is currently in focus and make session-id invalid or expires. driver.quit(): Closes all the browser windows and terminates the web driver session. Session-id becomes null. 31)What are the locator strategies in Selenium. Traditional Locators Id, Name, ClassName, TagName, Link text, Partial LinkText, Xpath, CSS Selector. Relative Locators above, below, Left of, Right Of, Near Locators can also be chained as per the latest Selenium 4 Release. By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("c

Latest Selenium Interview Questions And Answers.pdf

  • 1.
    1/6 By Varsha July2, 2021 Latest Selenium Interview Questions And Answers automationqahub.com/latest-selenium-interview-questions-and-answers/ 1)What is the difference between selenium 3 and selenium 4. Selenium 3 uses the JSON wire protocol and selenium 4 uses W3C standardization.  Native Support was removed for browsers like Opera and PhantomJs in selenium 4. Selenium IDE was only available as a Firefox extension in version 3. However, in selenium version 4 IDE is available for Chrome as well. Unlike selenium 3, Selenium 4 provides native support for chrome DevTools. Selenium 4 has introduced Relative locators that allow testers to find elements relative to another element in DOM. Docker support has been added to the Grid server for more efficient parallel execution. 2) Which selenium web driver locator should be preferred? ID is the preferred choice because it is less prone to changes, However, CSS is considered to be faster and is usually easy to read. XPath can walk up and down the DOM, which makes Xpath more customizable. 3)Explain difference between findElement() and find elements(). findElement(): This command is used for finding a particular element on a web page, it is used to return an object of the first found element by the locator. Throws NoSuchElementException if the element is not found. find elements(): This command is used for finding all the elements in a web page specified by the locator value. The return type of this command is the list of all the matching web elements. It returns an empty list if no matching element is found. 4)Explain the difference between Thread.Sleep() and selenium.setSpeed(). Thread.Sleep(): It causes the current thread to suspend execution for a specified period. selenium.setSpeed():setSpeed sets a speed that will apply a delay time before every Selenium operation. 5)How to handle stale element reference exception? The stale element exception occurs when the element is destroyed and recreated again in DOM. When this happens the reference of the element in DOM becomes stale. This can be handled in numerous ways.
  • 2.
    2/6 1)Refresh the pageand try to locate the stale element again. 2) Use Explicit wait to ignore the stale element exception. 3) Try to access the element several times in the loop(Usually not recommended.) 6)How many types of WebDriver APIs are available in selenium. Chrome, Geko Driver, Chromium, Edge. 7)How to open the browser in incognito mode. This can be done by using ChromeOptions class to customize the chrome driver session and adding the argument as “incognito”. ChromeOptions options = new ChromeOptions(); options.addArguments(“– incognito”); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); 8)How to handle file upload in selenium. File upload can be done in 3 ways: By using Robot class. By using sendkeys. By using AutoIt. 9)How many parameters are selenium required? Selenium requires four parameters: Host Port Number Browser URL 10)How to retrieve css properties of an element. driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”); driver.findElement(By.id(“id“)).getCssValue(“font-size”);  11)How can you use the Recovery Scenario in Selenium WebDriver? By using “Try Catch Block” within Selenium WebDriver Java tests. 12)How To Highlight Element Using Selenium WebDriver? Use Javascript Executor interface: JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("arguments[0].setAttribute('style', 'background: yellow; border: 2px solid red;');", element);
  • 3.
    3/6 13)Explain a fewadvantages of the Page Object Model. Readable and Maintainable code. Less and optimized code. Low redundancy. 14)List some Commonly used interfaces of selenium web driver. WebDriver TakesScreenshot JavascriptExecutor WebElement SearchContext 15)What is the difference between @FindAll and @Findbys. @FindBys: When the required WebElement objects need to match all of the given criteria use @FindBys annotation. @FindBys( { @FindBy(className = "class1") @FindBy(className = "class2") } ) private List<WebElement> ele //elements With Both_class1 AND class2; @FindAll: When required WebElement objects need to match at least one of the given criteria use the @FindAll annotation. @FindAll({ @FindBy(className = "class1") @FindBy(className = "class2") }) private List<WebElement> ele //elements With Either_class1 OR class2 ; 16)How to Click on a web element if the selenium click() command is not working. There are multiple ways provided by the selenium web driver to perform click operations. You can use either Action class or can leverage javascript executor. a) Javascript executor is an interface provided by selenium to run javascript through selenium web driver. import org.openqa.selenium.JavascriptExecutor; public void clickThruJS(WebElement element) { JavascriptExecutor executor = (JavascriptExecutor) Driver; executor.executeScript(“arguments[0].click();”, element); }
  • 4.
    4/6 b) Action classis provided by selenium to handle mouse and keyboard interactions. import org.openqa.selenium.interactions.Actions; public void ClickToElement(WebElement elementName) { Actions actions = new Actions(Driver); actions.moveToElement(elementName).perform(); actions.moveToElement(elementName).click().perform(); } 17)How to exclude a test method from execution in TestNG. By adding the exclude tag in the testng.xml file. <classes> <class name=”TestCaseName”> <methods> <exclude name=”TestMethodName”/> </methods> </class> </classes> 18)What are different ways of ignoring a test from execution. Making parameter “enabled” as “false”. Using the “exclude” parameter in testng.xml. “throw new SkipException()” in the if condition to Skip / Ignore Test. 19)What is the difference between scenario and scenario outline in cucumber? When we want to execute a test one time then we use the scenario keyword. If we want to execute a test multiple times with different sets of data then we use the scenario outline keyword. A scenario outline is used for data-driven testing or parametrization. We use example keywords to provide data to the scenario outline 20)What are different ways to reload a webpage in selenium? 1)Driver.navigate().refresh() 2)Driver.get(Driver.getCurrentUrl()) 3)Driver. findElement(By.id(“id”)).sendKeys(Keys.F5); 4)Driver.navigate().to(Driver.getCurrentUrl()) 21)What is the difference between getText() and getAttribute(). getText() method returns the text present which is visible on the page by ignoring the leading and trailing spaces, while the getAttribute() method returns the value of the attribute defined in the HTML tag. 22)How to disable Chrome notifications using selenium? You need to use chrome options to disable notifications on chrome:
  • 5.
    5/6 Map<String, Object> prefs= new HashMap<String, Object>(); prefs.put("profile.default_content_setting_values.notifications", 2); ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("prefs", prefs); WebDriver driver = new ChromeDriver(options); 23)What is the difference between @BeforeTest and @BeforeMethod? @BeforeTest will run only once before each test tag defined in testng.xml, however, @BeforeMethod will run before every method annotated with the @Test tag. In other words, every test in a file is a method but vice versa is not true, so no matter how many methods are annotated with @Test, @BeforeTest will be called only one time and @BeforeMethod executes before each test method. 24)Explain cucumberOptions with the keywords. @CucumberOptions enables us to define some settings for our tests, it works like the cucumber JVM command line. Using @CucumberOptions we can define the path of the feature file and the step definition file, we can also use other keywords to set our test execution properly. 25)What is cucumber DryRun? Dry Run is used to check the complete implementation of all the mentioned steps present in the Feature file. If it is set as true, then Cucumber will check that every Step mentioned in the Feature File has corresponding code written in the Step Definition file or not. 26)How to set the Priority of cucumber Hooks? @Before(order = int) : This runs in incremental order, like (order=0) will execute first then (order=1) and so on. @After(order = int): This executes in decremental order, which means value 1 would run first and 0 would be after 1. 27)What is a data table in cucumber and how to use it? Data tables are used when the scenario step requires to be tested with multiple input parameters, multiple rows of data can be passed in the same step and it’s much easier to read. Scenario: Valid Registration Form Information Given User submits a valid registration form | John | Doe |01-01-1990 |999999999 | Then System proceeds with registration 28)Explain invocation count in testNg.
  • 6.
    6/6 invocation count: Itrefers to the number of times a method should be invoked. It will work as a loop. Eg: @Test(invocation count = 7) . Hence, this method will execute 7 times. 29)Explain build().perform() in actions class. build()  This method in the Actions class is used to create a chain of action or operation you want to perform. perform()  This method is used toexecute a chain of actions that are built using the Action build method. 30)What is the difference between driver.close() and driver.quit()? driver. close(): Close the browser window which is currently in focus and make session-id invalid or expires. driver.quit(): Closes all the browser windows and terminates the web driver session. Session-id becomes null. 31)What are the locator strategies in Selenium. Traditional Locators Id, Name, ClassName, TagName, Link text, Partial LinkText, Xpath, CSS Selector. Relative Locators above, below, Left of, Right Of, Near Locators can also be chained as per the latest Selenium 4 Release. By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("c