Refer to the below Links for Practise |
Selenium Wiki |
- List the Java Classes available in Selenium API?
- List the Java Interfaces available in Selenium API?
- List the Abstract Class available in Selenium API?
- List the static methods available in Selenium API?
- What is the difference between List & Set?
- add
- size
- get
- remove(int index)
- remove(Object o)
- add
- size
- remove(object o)
- A Class extends more than one class??
- A Interface can extends more than one interface?
- How to capture the screenshot in Selenium?
- How to perform Drag and Drop in Selenium?
-
What is StaleElementReference Exception?
- The element has been deleted entirely.
- The element is no longer attached to the DOM. It happens generally when the page is getting refreshed.
- What is NullPointerException?
- What happens when you interact with the Element which is hidden?
- What is the difference findElement and findElements?
- Write the logic to get the visibility of the element using JavascriptExecutor?
- How to retrieve the color of an element?
- How to handle an Alert?
- Write logic to wait an Alert?
- Write logic to wait for an Element?
- Write logic to wait for textToBePresent?
- Write logic to wait for title?
- Write logic to identify element using JavaScriptExecutor?
- Write logic to upload a file?
- Write logic to copy the file one location to another location?
- What is the method used to refresh the page?
- Write the logic to scroll to a particular element?
- Write the logic to capture the full screenshot using Robot Class?
- Write the logic to convert the String to a Double?
- Write the logic to convert the String to a Integer?
-
Write the logic to verify Element is Enabled?
- Write the logic to verify the Element is visible?
- Write the logic to check if radio/checkbox is Selected?
- What are the different Components of Selenium?
- Selenium IDE[Integrated Development Environment]
- Selenium RC[Remote Control]
- Selenium WebDriver
- Selenium Grid[Useful to invoke the browser on a remote desktop without copying the source code]
- What is the usage of HtmlUnitDriver?
- What is the method used to delete all the cookies in Selenium?
- What is the method used to perform right click in Selenium?
- What is method used to perform double click in Selenium?
- What is the difference between click and submit in Selenium?
- What is the difference between linkText and PartialLinkText?
- List all the Exception which come across in Selenium?
- What are the Challenges in Selenium?
- What is the method used to get all the items in the List?
- What is the advantage of writing WebDriver driver = new FirefoxDriver();
- What is the default port of Selenium Hub ??
- Write the logic to configure the poll time out?
- How to debug the code in Selenium?
- What is mandatory method called to perform sequence of mouse Actions?
-
What is the method used to get the “id” value of an WebElement?
- Is it possible to verify the image?
- Is it possible automating Windows Dialog in Selenium?
- List all the different navigation methods in Selenium?
Select,ExpectedConditions,RemoteWebDriver,FirefoxDriver,
ChromeDriver,InternetExplorerDriver,DesiredCapabilities,
WebDriverWait,Action,Point,Proxy,Rectangle
WebDriver,JavascriptExecutor,TakesScreenshot,WebElement
By
xpath(),id(),name(),tagName(),linkText(),partialLinkText(),cssSelector()
List is useful to store object which are duplicate as well.
List list = new ArrayList();
List list = new Vector();
List list = new LinkedList();
Set is useful to store only unique objects. It doesn’t allow duplicates.
Set set = new HashSet();
Set set = new TreeSet();
Set set = new LinkedHashSet();
Using ITerator or Enhanced for loop to retrieve elements from the Set.
Due to diamond problem in java multiple inheritances is not allowed. So, a class can extend only one class at a time as mentioned below.
Example: public class FirefoxDriver extends RemoteWebDriver
Yes. Example: public interface C extends A,B // A & B are interfaces
File screenshotFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String screenshotBase64 = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
Actions action = new Actions(WebDriver);
action.dragAndDrop(sourceWE, destWE)
A stale element reference exception is thrown in one of two cases, the first being more common than the second:
To overcome this either we need to findElement again else we ignore finding the Element which is deleted from DOM. DOM Stands for Document Object Model, the html components are structured in DOM Tree.
NullPointerException is a RuntimeException . In Java, a special null value can be assigned to an object reference. NullPointerException is thrown when an application attempts to use an object reference that has the null value.
To overcome this, we need assign the value for the reference variable contains null.
FirefoxDriver driver; //Contains null value
driver.get(String url);// throws NullpointerException
Solution:
FirefoxDriver driver = new FirefoxDriver();
driver.get(String url);
org.openqa.selenium.ElementNotVisibleException
findElement
1. WebElement e = driver.findElement(By.name("username"));
findElement(By) returns an WebElement as a return value.
2. findElement(By) throws an exception if it is unable to find an Element.
WebElement e =driver.findElement(By.name(“abc”));
NoSuchElementException is an RunTimeException/Unchecked Exception
3. findElement(By) always selects the first one in the list of matching WebElements.
If we want to select other then frist one, we have to use xpath or cssSelector.
4 in number.
driver.findElement(By.tagName(“input”))’ will select first one
findElements(By)
1. findElements(By) returns an List of WebElements
2.findElements(By) returns an empty list if its unable to find an element
List<WebElement> list = driver.findElements(By.name("abc"));
Empty List means list.size() is zero.
3. findElements(By) selects all the matching webElements and returns a list.
WebElement element = driver.findElement(By.id(""));
Object o = ((JavascriptExecutor) driver).
executeScript("arguments[0].scrollIntoView(true);", element);
element = (WebElement) o;
element.click();
getCssValue(“color”)
getCssValue(“background-color”)
Alert alrt = driver.switchTo().alert();
alrt.accept();
WebDriverWait wait = new WebDriverWait(driver,30);
boolean result = wait.until(ExpectedConditions.isAlertPresent()));
WebDriverWait wait = new WebDriverWait(driver,30);
WebElement e=wait.until(ExpectedConditions.visibilityOfElementLocated(By locator));
WebDriverWait wait = new WebDriverWait(driver,30);
boolean result = wait.until
(ExpectedConditions.textToBePresentInElementLocated(By locator,java.lang.String text));
WebDriverWait wait = new WebDriverWait(driver,30);
boolean result = wait.until(ExpectedConditions.titleContains (java.lang.String title));
Object o = ((JavascriptExecutor) driver).executeScript("return document.getElementById(‘idvalue’));
element = (WebElement) o;
driver.findElement(By.id(“uploadbuttonid”)).sendKeys(“AbsolutePathto File”));
FileUtils.copyFile(srcLocation,destLocation);
driver.navigate().refresh();
(JavascriptExecutor) driver).executeScript(“scroll(height,width)”);
BufferedImage image = new Robot().
createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(image, "png", new File("C:\\Screenshot.jpg"));
String str=”2,567.65”;
double d = Double.parseDouble(str.replace(“,”,””));
String str=”2,567”;
int d = Integer.parseInteger(str.replace(“,”,””));
WebElement e = driver.findElement();
boolean result = e.isEnabled();
WebElement e = driver.findElement();
boolean result = e.isDisplayed();
WebElement e = driver.findElement();
boolean result = e.isSelected();
Useful to simulate the behavior of the browser. This helps to execute the scripts without launching the browser.
driver.manage().deleteAllCookies();
Actions contextClick(WE);
Actions doubleClick(WE);
If this current element is a form, or an element within a form, then this will be submitted to the remote server.
Else use click method to perform operation on a button.
LinkText-locates A elements by the exact text they display.
PartialLinkText-locates A elements that contain the given text.
NoSuchElementException
NoSuchFrameException
NoSuchWindowException
AlertNotPresentException
StaleElementReferenceException
ElementNotVisibleException
Identification of Locators.
Execution of tests against multiple browsers
Designing the Framework
Handling wait statements
Select select = new Select(WebElement);
List<WebElement> itemsList= select.getOptions();
WebDriver is an Interface and implemented by FirefoxDriver Class.
During cross browser testing for executing the same tests against the multiple browser.
We declare the left hand side variable as WebDriver and Right hand side create an object for particular
type of browser and assign.
WebDriver driver;
driver = new FirefoxDriver();
driver = new ChromeDriver();
driver = new InternetExplorerDriver();
Default port is 4444
// Waiting 30 seconds for an element to be present on the page, checking
// for its presence once every 5 seconds.
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
WebElement foo = wait.until(ExpectedConditions.visibilityOfElementLocated(By locator));
By inserting the breakpoint and debug the code in Eclipse.
(Step Into) go into that method and continue debugging step-by-step.
(Step Over) to execute that method completely as one entire step without getting into that method
perform() method to be called in the end to perform sequence of mouse actions.
WebElement e = driver.findElement();
String idValue = e.getAttribute(“id”);
No. In Selenium we cannot verify the contents of the image but we can verify the image displayed or not by using the properties. Same is applicable for BarCode and captcha images as well.
No. We have to use AutoIT to handle windows Dialogs.
driver.navigate().to(String url);
driver.navigate().refresh();
driver.navigate().foward();
driver.navigate().back();