Selenium :
1.What is polymorphism
2.Example of run time and Compile time polymorphism in Selenium
a)WebDriver driver =new ChromeDriver();
Web Driver is an Interface.
driver.gettitle();driver.getPageSource ,driver.getURL() are methods which can inherit different classes as per Browser giver.
Thread.sleep() is also an example of it .
b)Complile time :
wait.driver() has different number of arguments :
defatult wait.driver.
wait.driver(long timeout)
wait.driver(long timeout,int nano
3)Different waits in Selenium
4)Thread.sleep() is implicit or explicit wait ?
Explicit Waits
An explicit wait is code you define to wait for a certain condition to occur before proceeding further in the code. The worst case of this is Thread.sleep(), which sets the condition to an exact time period to wait. There are some convenience methods provided that help you write code that will wait only as long as required. WebDriverWait in combination with ExpectedCondition is one way this can be accomplished.
Implicit wait :
5)Difference between Abstract and Interface..?-
Refer Link -
https://www.journaldev.com/1607/difference-between-abstract-class-and-interface-in-java
https://www.javatpoint.com/difference-between-abstract-class-and-interface
-----------------
6)How can we handle mouse action
Action ac=new action(driver);
mouser hover using
ac.movetoelement(ele).build;
ac.doubleclick(ele);
The build() method is always the final method used so that all the listed actions will be compiled into a single step.
6 b)What is difference between build() and perform() action.
The build() method is used compile all the listed actions into a single step.
we have to use build() when we are performing sequence of operations and no need to use only if we are performing single action.
example :
Actions builder = new Actions(driver);
builder.clickAndHold((WebElement)listItems.get(0)).clickAndHold((WebElement)listItems.get(3)).click().build().perform();
..
7)How to find Broken links ..?
List<WebElement> link=driver.findElements(By.tagname("href"));
int linksize =link.size();
for (int i=0;i<linksize;i++)
{
Webelement ele=link.get(i);
String url =el.getAttribute("href");
Verify(url);
}
public static void url(String url)
{
try{
URL link=new URL(url);
HttpURLConnection httpConn=(HttpURLConnection)link.openConnection();
httpConn.setConnectTimeout(2000);
httpConn.connect();
//user get response
if(httpConn.getResponseCode()==200)
{
System.out.println(url+"-"+httpConn.getResponseMessage());
}
if(httpConn.getResponseCode()==500)
{
System.out.println(url+"-"+httpConn.getResponseMessage());
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
8)what is Dyanmic Xpath :
example -
package testpack;
public class AbstractEx {
abstract void test();
}-
---
10)What are order of execution in Testng
11)Grid
12)Example for Abstract in Selenium :
Refer link: http://artoftesting.com/interviewSection/selenium-interview-questions.html
1)What are different forms of selenium?
Quest 4 :What are some limitations of selenium?
Ques.5. Which all browsers/drivers are supported by Selenium Webdriver?
Ans. Some commonly used browsers supported by selenium are-
Ans. No selenium webdriver uses browser's native method to automate the web applications. Since web services are headless, so we cannot automate web services using selenium webdriver.
Ques.8. What are various ways of locating an element in selenium?
Ans. The different locators in selenium are-
10) What is Relative xpath
Ques.12. What is the difference between single slash(/) and double slash(//) in XPath?
Ans. In XPath a single slash is used for creating XPaths with absolute paths beginning from root node.
Whereas double slash is used for creating relative XPaths.
How can we locate an element by only partially matching its attributes value in Xpath?
How can we locate elements using their text in XPath?
How can we move to parent of an element using XPath?
What is the syntax of finding elements by class using CSS Selector?
What is the use of driver.get("URL") and driver.navigate().to("URL") command? Is there any difference between the two?
Both driver.get("URL") and driver.navigate().to("URL") commands are used to navigate to a URL passed as parameter.
Explain the difference between close and quit command.
How to switch between multiple windows in selenium?
Whereas driver.getWindowHandles() returns a set of handles of the all the pages available.
How can we move to a particular frame in selenium?
The driver.switchTo() commands can be used for switching to frames.
For locating a frame we can either use the index (starting from 0), its name or Id.
What is difference between gettagname(),gettext() and getattribute()
Ques.38. How to delete cookies in selenium?
Ans. Using deleteAllCookies() method-
Ques.40. What is an explicit wait in selenium?
Ans. An explicit wait is a type of wait which is applied to a particular web element untill the expected condition specified is met.
Ans. Some of the commonly used expected conditions of an element that can be used with expicit waits are-
Ans. A fluent wait is a type of wait in which we can also specify polling interval(intervals after which driver will try to find the element) along with the maximum timeout value.
1.What JVM and JRE
2.difference between final ,constant and static
---
What is difference between WindowHandle and Window.Handles()
data count of Window Handles ()..?
--
What is a concrete Class?
- -
Use of Interface in java -
1.Interface can only have static ,public ,final variables -else it through the error messgae.
2. For method we can only public, abstract, default, static and strictfp are permitted-

3. Static is not allowed for interface Illegal modifier for the interface Testinterface1; only public &
abstract are permitted

4. for Class we can have it public,abstract and final for abstract method
5. We cannot use abstract method directly in interace -if using abstract method in the interface in psvm or through other annotation -it will give the error -
"Cannot make a static reference to the non-static method teststring() from the type Testinterface1" .
6. If class impementing interface it must have the abstract methods implented or class should be declared static.
error thrown -
"The type TestclassIntefaceImplement must implement the inherited abstract method Testinterface1.printteststring()"
1.What is polymorphism
2.Example of run time and Compile time polymorphism in Selenium
a)WebDriver driver =new ChromeDriver();
Web Driver is an Interface.
driver.gettitle();driver.getPageSource ,driver.getURL() are methods which can inherit different classes as per Browser giver.
Thread.sleep() is also an example of it .
b)Complile time :
wait.driver() has different number of arguments :
defatult wait.driver.
wait.driver(long timeout)
wait.driver(long timeout,int nano
3)Different waits in Selenium
4)Thread.sleep() is implicit or explicit wait ?
Explicit Waits
An explicit wait is code you define to wait for a certain condition to occur before proceeding further in the code. The worst case of this is Thread.sleep(), which sets the condition to an exact time period to wait. There are some convenience methods provided that help you write code that will wait only as long as required. WebDriverWait in combination with ExpectedCondition is one way this can be accomplished.
Implicit wait :
driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);
5)Difference between Abstract and Interface..?-
abstractkeyword is used to create an abstract class and it can be used with methods also whereasinterfacekeyword is used to create interface and it can’t be used with methods.- Subclasses use
extendskeyword to extend an abstract class and they need to provide implementation of all the declared methods in the abstract class unless the subclass is also an abstract class whereas subclasses useimplementskeyword to implement interfaces and should provide implementation for all the methods declared in the interface. - Abstract classes can have methods with implementation whereas interface provides absolute abstraction and can’t have any method implementations. Note that from Java 8 onwards, we can create default and static methods in interface that contains the method implementations.
- Abstract classes can have constructors but interfaces can’t have constructors.
- Abstract class have all the features of a normal java class except that we can’t instantiate it. We can use
abstractkeyword to make a class abstract but interfaces are a completely different type and can have only public static final constants and method declarations. - Abstract classes methods can have access modifiers as public, private, protected, static but interface methods are implicitly public and abstract, we can’t use any other access modifiers with interface methods.
- A subclass can extend only one abstract class but it can implement multiple interfaces.
- Abstract classes can extend other class and implement interfaces but interface can only extend other interfaces.
- We can run an abstract class if it has
main()method but we can’t run an interface because they can’t have main method implementation. - Interfaces are used to define contract for the subclasses whereas abstract class also define contract but it can provide other methods implementations for subclasses to use.
Interface or Abstract Class
Whether to choose between Interface or abstract class for providing a contract for subclasses is a design decision and depends on many factors. Let’s see when Interfaces are the best choice and when can we use abstract classes.- Java doesn’t support multiple class level inheritance, so every class can extend only one superclass. But a class can implement multiple interfaces. So most of the times Interfaces are a good choice for providing the base for class hierarchy and contract. Also coding in terms of interfaces is one of the best practices for coding in java.
- If there are a lot of methods in the contract, then abstract class is more useful because we can provide a default implementation for some of the methods that are common for all the subclasses. Also if subclasses don’t need to implement a particular method, they can avoid providing the implementation but in case of interface, the subclass will have to provide the implementation for all the methods even though it’s of no use and implementation is just empty block.
- If our base contract keeps on changing then interfaces can cause issues because we can’t declare additional methods to the interface without changing all the implementation classes, with the abstract class we can provide the default implementation and only change the implementation classes that are actually going to use the new metho
Refer Link -
https://www.journaldev.com/1607/difference-between-abstract-class-and-interface-in-java
https://www.javatpoint.com/difference-between-abstract-class-and-interface
-----------------
6)How can we handle mouse action
Action ac=new action(driver);
mouser hover using
ac.movetoelement(ele).build;
ac.doubleclick(ele);
The build() method is always the final method used so that all the listed actions will be compiled into a single step.
6 b)What is difference between build() and perform() action.
The build() method is used compile all the listed actions into a single step.
we have to use build() when we are performing sequence of operations and no need to use only if we are performing single action.
example :
Actions builder = new Actions(driver);
builder.clickAndHold((WebElement)listItems.get(0)).clickAndHold((WebElement)listItems.get(3)).click().build().perform();
..
7)How to find Broken links ..?
List<WebElement> link=driver.findElements(By.tagname("href"));
int linksize =link.size();
for (int i=0;i<linksize;i++)
{
Webelement ele=link.get(i);
String url =el.getAttribute("href");
Verify(url);
}
public static void url(String url)
{
try{
URL link=new URL(url);
HttpURLConnection httpConn=(HttpURLConnection)link.openConnection();
httpConn.setConnectTimeout(2000);
httpConn.connect();
//user get response
if(httpConn.getResponseCode()==200)
{
System.out.println(url+"-"+httpConn.getResponseMessage());
}
if(httpConn.getResponseCode()==500)
{
System.out.println(url+"-"+httpConn.getResponseMessage());
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
8)what is Dyanmic Xpath :
Dynamic XPath: Dynamic XPath is also called as custom XPath and it is one way to locate element uniquely.
Dynamic XPath is used to locate exact attribute or decrease the number of matching nodes/result from a webpage and following XPath expressions can be used for the same:
- Contains
- Sibling
- Ancestor
- //*[@class='product']//h4[contains(text(),'Text')]//ancestor::div[@class='table-good'] .//*[@class='product']//h4[contains(.,'Text')]//ancestor::div[@class='table-good']
- 9)Can abstract method exist in non abstract class ? .
example -
package testpack;
public class AbstractEx {
abstract void test();
}-
---
10)What are order of execution in Testng
11)Grid
12)Example for Abstract in Selenium :
Refer link: http://artoftesting.com/interviewSection/selenium-interview-questions.html
1)What are different forms of selenium?
- Selenium WebDriver - Selenium WebDriver is used to automate web applications using browser's native methods.
- Selenium IDE - A firefox plugin that works on record and play back principle.
- Selenium RC - Selenium Remote Control(RC) is officially deprecated by selenium and it used to work on javascript to automate the web applications.
- Selenium Grid - Allows selenium tests to run in parallel across multiple machines.
Quest 4 :What are some limitations of selenium?
Ques.5. Which all browsers/drivers are supported by Selenium Webdriver?
Ans. Some commonly used browsers supported by selenium are-
- Google Chrome - ChromeDriver
- Firefox - FireFoxDriver
- Internet Explorer - InternetExplorerDriver
- Safari - SafariDriver
- HtmlUnit (Headless browser) - HtmlUnitDriver
- Android - Selendroid/Appium
- IOS - ios-driver/Appium
Ans. No selenium webdriver uses browser's native method to automate the web applications. Since web services are headless, so we cannot automate web services using selenium webdriver.
Ques.8. What are various ways of locating an element in selenium?
Ans. The different locators in selenium are-
- Id
- XPath
- cssSelector
- className
- tagName
- name
- linkText
- partialLinkText
10) What is Relative xpath
Ques.12. What is the difference between single slash(/) and double slash(//) in XPath?
Ans. In XPath a single slash is used for creating XPaths with absolute paths beginning from root node.
Whereas double slash is used for creating relative XPaths.
How can we locate an element by only partially matching its attributes value in Xpath?
How can we locate elements using their text in XPath?
How can we move to parent of an element using XPath?
What is the syntax of finding elements by class using CSS Selector?
What is the use of driver.get("URL") and driver.navigate().to("URL") command? Is there any difference between the two?
Both driver.get("URL") and driver.navigate().to("URL") commands are used to navigate to a URL passed as parameter.
Explain the difference between close and quit command.
How to switch between multiple windows in selenium?
for (String windowHandle : driver.getWindowHandles()) { driver.switchTo().window(handle); }
What is the difference between driver.getWindowHandle() and driver.getWindowHandles() in selenium?
Ans. driver.getWindowHandle() returns a handle of the current page (a unique identifier)Whereas driver.getWindowHandles() returns a set of handles of the all the pages available.
How can we move to a particular frame in selenium?
The driver.switchTo() commands can be used for switching to frames.
driver.switchTo().frame("{frameIndex/frameId/frameName}");
What is difference between gettagname(),gettext() and getattribute()
Ques.38. How to delete cookies in selenium?
Ans. Using deleteAllCookies() method-
driver.manage().deleteAllCookies()
Quest 39. What is an implicit wait in selenium?
Ans. An implicit wait is a type of wait which waits for a specified
time while locating an element before throwing NoSuchElementException.
By default selenium tries to find elements immediately when required
without any wait. So, it is good to use implicit wait. This wait is
applied to all the elements of the current driver instance.driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Ques.40. What is an explicit wait in selenium?
Ans. An explicit wait is a type of wait which is applied to a particular web element untill the expected condition specified is met.
WebDriverWait wait = new WebDriverWait(driver, 10); WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("elementId")));
Ques.41. What are some expected conditions that can be used in Explicit waits?
Ans. Some of the commonly used expected conditions of an element that can be used with expicit waits are-
- elementToBeClickable(WebElement element or By locator)
- stalenessOf(WebElement element)
- visibilityOf(WebElement element)
- visibilityOfElementLocated(By locator)
- invisibilityOfElementLocated(By locator)
- attributeContains(WebElement element, String attribute, String value)
- alertIsPresent()
- titleContains(String title)
- titleIs(String title)
- textToBePresentInElementLocated(By, String)
Ans. A fluent wait is a type of wait in which we can also specify polling interval(intervals after which driver will try to find the element) along with the maximum timeout value.
Wait wait = new FluentWait(driver) .withTimeout(20, SECONDS) .pollingEvery(5, SECONDS) .ignoring(NoSuchElementException.class); WebElement textBox = wait.until(new Function<webdriver,webElement>() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("textBoxId")); }
What is Robot API? }
Robot API is used for handling Keyboard or mouse events. It is
generally used to upload files to the server in selenium automation.
Robot robot = new Robot(); //Simulate enter key action robot.keyPress(KeyEvent.VK_ENTER);
How to do file upload in selenium?Ans. File upload action can be performed in multiple ways-
- Using element.sendKeys("path of file") on the webElement of input tag and type file i.e. the elements should be like -
<input type="file" name="fileUpload">
- Using Robot API.
- Using AutoIT API.
);
Java :1.What JVM and JRE
2.difference between final ,constant and static
---
What is difference between WindowHandle and Window.Handles()
data count of Window Handles ()..?
--
What is a concrete Class?
- -
Use of Interface in java -
1.Interface can only have static ,public ,final variables -else it through the error messgae.
2. For method we can only public, abstract, default, static and strictfp are permitted-
3. Static is not allowed for interface Illegal modifier for the interface Testinterface1; only public &
abstract are permitted
4. for Class we can have it public,abstract and final for abstract method
5. We cannot use abstract method directly in interace -if using abstract method in the interface in psvm or through other annotation -it will give the error -
"Cannot make a static reference to the non-static method teststring() from the type Testinterface1" .
6. If class impementing interface it must have the abstract methods implented or class should be declared static.
error thrown -
"The type TestclassIntefaceImplement must implement the inherited abstract method Testinterface1.printteststring()"
No comments:
Post a Comment