Selenium Question

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Questions Answer

What are the different types of locators in Selenium? id,Name,Linktext,Partial Linktext,Tag Name,Class Name,Css,Xpath

What the difference is between assert and verify commands? Assert: Assert command checks whether the given condition is true or
false. If the condition is true then the program control will execute the next
test step but if the condition is false, the execution would stop and no
further test would be executed.
Verify: Verify command also checks whether the given condition is true or
false. Irrespective of the condition being true or false, the program
execution doesn’t halt i.e. any failure during verification would not stop the
execution and all the test steps would be executed.

What is an XPath? XPath is used to locate a web element based on its XML path.

What is the difference between “/” and “//” in Xpath? Single Slash “/” – Single slash is used to create Xpath with absolute path
Double Slash “//” – Double slash is used to create Xpath with relative path

How do I launch the browser using WebDriver? The following syntax can be used to launch Browser:
WebDriver driver = new FirefoxDriver();
WebDriver driver = new ChromeDriver();
WebDriver driver = new InternetExplorerDriver();

What are the different types of waits available in WebDriver? Implicit Wait :

Applied on entire page

Once you declared implicit wait it will be available for the entire life
of web driver instance

Wait is suggested

Implicit Wait is applicable for all web elements that are on a web
page
Explicit Wait:

Applied on an element

It will be used if we want the execution to wait for some time until
some condition achieved.

Wait is directly expressed

Explicit wait can applied against a single or multiple web elements

How can you find if an element in displayed on the screen? isDisplayed()


isSelected()
isEnabled()

How to find more than one web element in the list? List <WebElement> elementList =
driver.findElements(By.xpath("//div[@id='example']//ul//li"));
int listSize = elementList.size();
for (int i=0; i<listSize; i++)
{
serviceProviderLinks.get(i).click();
link to service providers
driver.navigate().back();
}

Can Selenium handle windows based pop up? Selenium is an automation testing tool which supports only web
application testing. Therefore, windows pop up cannot be handled using
Selenium. It can handle window based through third party tool like
AUTOIT.

Reverse a string using java program public static String reverse(String source){
if(source == null || source.isEmpty()){
return source;
}
String reverse = "";
for(int i = source.length() -1; i>=0; i--){
reverse = reverse + source.charAt(i);
}
return reverse;
}

Explain JVM, JRE and JDK?

WebDriver is an interface and all the abstract method like get(),navigate()


What is webdriver ?why is it used method are provided by webdriver

Different ways to click element 1.Element.click()


2.Through JavascriptExecutor

How to handle dynamic element in selenium We can use different xpath method for this
For Ex-:
Startwith()
Endswith()
2.Through wait command

What is explicit wait? can you list some conditions given in explicit wait Conditions-:
1.IsAlertPresent
2.Is ElementClickable
3.IsElementVisible
And much more

Challenges faced in automating the webpage 1.Handling dynamic element


2.cant capture the captcha
3.Timeunit defined in the wait condition
4.Xpath in IE is slower than xpath in firefox

Difference between thread.sleep and implicit wait Thread.sleep will make entire webpage to go on sleep even if the element
has been found but in implicit wait , if the element is found it will move to
next condition .so thread.sleep will slow down the webpage

What is stale exception? How to handle stale exception Stale exception occurs when element is no longer found in dom or
element has been changed
We can handle it with putting the path of element in
for loop and give the count as 3 or 2 times and handle it through try catch
exception
public boolean retryingFindClick(By by) {
boolean result = false;
int attempts = 0;
while(attempts < 2) {
try {
driver.findElement(by).click();
result = true;
break;
} catch(StaleElementException e) {
}
attempts ++;
}
return result;
}

Different type of exception occurs in selenium 1. Stale exception 2.ElementNotFound Exception.


3.TimeOut Exception 4.Element Not Found Exception

FireFoxDriver driver = new FirefoxDriver..Is this a correct statement Yes, it will absolutely work fine. But if we want to use the reference driver
to launch other browser it will throw error

If there is duplicate element present in the webpage having same Duplicate element can be handled as below-:
xpath?How to handle that
1.Check their parent id , if parent id is different we can call the element by
the parent id
2.We can put the number for element
Like-:
//input[@type=’element’][1]
//input[@name=’element’][2]

Different between findElement and findElements FindElement - return the first find Element, If element not found thrown
element not found exception
FindElements - return the list of element ,if element not found it return the
empty string
If element is not identified through xpath and css locator , how can Through java-script executor
going to address that

How to right click on selenium Through actions class


Action a=new Actions()
a.contextclick()build().perform()

What are the annotation used in Testng.Name them in way they are @BeforeSuite @BeforeClass @BeforeTest @BeforeMethod
executed
@Test @AfterMethod @AfterTest @AfterClass @AfterSuite

What are dataProvider in testng DataProvider provide the static data to program .It returns the array of
objects[][]
@dataProvider

How did you achieve api automation? If used java, which library used Examples: restassured, httpclient

How did you achieve api automation? If used python, which module Requests, json,
used

How do you install modules in python Using pip

Write a program to remove duplicates from string in python before = 'aaabbbac'


after = ''.join(sorted(set(before)))
n_removed = len(before) - len(after)

Count the number of characters in a string using collections in python import collections
results = collections. Counter(the_string)
print(results)

I used open command to launch my page, but I encountered timeout This happens because open commands wait for only 30 seconds for a
error. page to load. If your application takes more than 30 sec then you can use
“setTimeout (timeout)” to make selenium IDE wait for specified time,
before proceeding with test execution.

You might also like