How can we submit a form using Selenium?
You can submit form in Selenium using below code snippet
What is difference between findElement() & findElements()?
Syntax: WebElement element = webdriver.findElement(By.id(“item_id”));
Syntax: List<WebElement> element = webdriver.findElements(By.id(“item_id”));
What is the difference between click() & submit() in Selenium?
Submit() both are used to click button in web page.
Selenium Web Driver provides the special method
submit() to submit any form.
Submit() method works same as clicking on submit button.
Submit(): We can use
submit() method for only submit form. There are some restrictions that are given below:-
type="submit"& button should be inside
<form>tag, then only
submit()method will work.
submit()will not work.
submit()will not work.
Click(): We can use
click() method to click on any button. There is no restrictions for click.
type="submit", then click method will work for both type.
<form>tag or outside the
<form>tag, then click method will work.
What are different types of annotation which are useful?
Different types of annotations which are useful are listed below-
What are the different types of waits available in WebDriver?
Selenium WebDriver provides the two types of wait:
Implicit Wait: Implicit provides the facility to poll the DOM for a certain amount of time when trying to find the element if they are not immediatlely. Default time setting is
WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get("https://www.modernpathshala.com/"); WebElement element = driver.findElement(By.id("Element_Id"));
Explicit Wait: An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code. The worst case of this is
time.sleep(), which sets the condition to an exact time period to wait.
WebDriver driver = new FirefoxDriver(); driver.get("https://www.modernpathshala.com/"); WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));
What is difference between driver.close() and driver.quit()?
It is used to close the browser or page currently which is having the focus.
It is used to shut down the web driver instance or destroy the web driver instance means close all the browser windows. Basically it calls the driver.dispose method which in turn close s all the browser windows and ends the web driver session gracefully.
How to capture screenshot in WebDriver?
We can take the screenshot in WebDriver using this command.
File sourceFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(sourceFile, new File("D:\\my_screenshot.png"));
What is the TextNG?
TextNG is a testing framework for Java programing language and designed to simplify a broad range of testing needs, from unit testing to integration testing(testing entire system made of several classes and packages). In other words, TextNG is designed to cover all categories of testing like unit, end-to-end, functional, integration etc. where NG means Next Generation. It is an open source framework and inspired by JUnit. It is similar to Junit and designed to be better than Junit.