81. Can I navigate back and forward in a browser in Selenium WebDriver?
Answer: We can use navigate Interface to navigate back and forward in a browser. It has methods to move back, forward as well as to refresh a page.
driver.navigate().forward(): to navigate to the next web page with reference to the browser”s history.
driver.navigate().back(): takes back to the previous web page with reference to the browser’s history.
driver.navigate().refresh(): to refresh the current web page thereby reloading all the web elements.
driver.navigate().to(“url”): To launch a new web browser window and navigate to the specified URL.
82. How to fetch the current page web page URL in selenium?
Answer: To fetch the current page URL, we use getCurrentUrl().
Ex: driver.getCurrentUrl();
83. How can we maximize browser window in Selenium?
Answer: To maximize browser window in selenium we use maximize() method. This method maximizes the current window if it is not already maximized.
Ex: driver.manage().window().maximize();
84. How to delete cookies in Selenium?
Answer: To delete cookies we use deleteAllCookies() method.
Ex: driver.manage().deleteAllCookies();
85.What are the ways to refresh a browser using Selenium WebDriver?
Answer:
1. Using driver.navigate().refresh() command .
2. Using driver.get(“URL”) on the current URL or using driver.getCurrentUrl().
3. Using driver.navigate().to(“URL”) on the current url or driver.navigate().to(driver.getCurrentUrl());
4. Using sendKeys(Keys.F5) on any textbox on the webpage.
86. What is the difference between driver.getWindowHandle() and driver.getWindowHandles() in selenium Webdriver?
Answer:
driver.getWindowHandle() returns a handle of the current page ( a unique identifier ).
driver.getWindowHandles() returns a set of handles of all the pages available.
87: What is the difference between driver.close() and driver.quit()?
Answer:
driver.close() will close the current WebDriver instance.
driver.quit() will close all the opened WebDriver instances.
88. How to find whether an element is displayed on the web page?
Answer: WebDriver facilitates the user with following methods to check the visibility of the web elements. These web elements can be button, drop boxes, check boxes, radio buttons, labels, etc.
1 .isDisplayed() is the method used to verify the presence of a web element within the web page. The method returns a “true” value if the web element is present on the web page and a “false” value if the web element is not present on the web page. It is capable to check for the presence of all kinds of elements available.
2 . isEnabled() is the method used to verify if the web element is enabled or disabled within the web page. It is primarily used with buttons.
3 . isSelected() is the method used to verify if the web element is selected or not. It is predominantly used with Radio buttons , drop downs, and check boxes.
89. How to select a value in a dropdown?
Answer: By using Select class.
Ex: WebElement ele = driver.findElement(By.xpath(“xpaths”));
Select drop = new Select (ele);
drop.selectByVissibleText(Text);
drop.selectByIndex(Index);
drop.selectByValue(value);
90. How to handle windows based pop up?
Answer: If the pop up type is of file type, we can use send keys to handle it. Selenium doesn’t support windows based pop up. We could handle windows based pop ups in Selenium using some third party tools such as AutoIT, Robot Class, Sikuli, etc.
hi,your blog is very useful. all the questions are so challenging. thank you for posting all important questions.
http://www.trainingpune.in/selenium-training-in-pune.html