Selenium Question
Selenium Question
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 :
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.
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;
}
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
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;
}
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
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
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.