This blog is for Automation Test Engineers

Tuesday 29 August 2017

Interview Questions for Selenium WebDriver


1)Tell me about yourself?
2)Tell me about your project?
3)Challenges faced in Selenium?
4)Types of locators?
5)What is polymorphism and tell me where have used in your project?
6)What is encapsulation and tell me where have used in your project?
7)Different annotations used in TestNG?
8)Challenges faced in your project?
9)How do you handle dynamic elements?
10)What is Dataprovider?
11)How do u handle dynamic elements?
12)Explain framework that u have used?




0

How to print the contents of excel file



FileInputStream fis=new FileInputStream("E:\\test.xlsx");
Workbook wb=new WorkbookFactory.create(fis);
Sheet s=wb.geSheet("Sheetname");
int rowcount=s.getLastRowNum();
for(int j=0;j<rowcount;j++){
Row r =s.getRow(j);
int columncount=r.getLastCellNum();
for(int a=0;a<columcount;a++){
Cell c=r.getCell(a);
String s=c .getStringCellValue();
System.out.println(s);
}


0

How to retrieve data from notepad

FileInputStream fis=new FileInputStream("xyz.txt");
int j=0;
while(j=fis.read()!=-1){
System.out.println(char)j);
}
fos.close();

}


0

How to write contents in notepad


FileOutputStream fos=new FileOutputStream("xyz.txt");
String s="JavaSelenium";
byte b[]=s.getBytes();
fos.write(b);
fos.close();


0

Sunday 27 August 2017

How to use Trim function


By using trim method we can remove space before and after specified string

Eg;
String str="      SeleniumJava    ".trim();
System.out.print(str);


0

How to Zoom in and Zoom out

WebDriver driver=new FirefoxDriver();
driver.get("https://www.google.co.in/");
WebElement searchtextbox=driver.findElement(By.name("q")):
//zoom in
searchtextbox.sendkeys(Keys.chord(Keys.Control,Keys.ADD));

//zoom out
searchtextbox.sendkeys(Keys.chord(Keys.Control,Keys.SUB));




0

How to handle file download popup

searchtextbox.sendkeys(Keys.chord(Keys.Control,Keys.SUB));
WebDriver driver=new FirefoxDriver();
driver.get("https://www.seleniumhq.org/download/");
Firefoxprofile profile=new Firefoxprofile();
String Key=browser.helperApps.neverAsk.SaveToDisk";
String value="application/zip";
profile.setpreference(key.value);
Webdriver driver=new FirefoxDriver(profile);
driver.findElement(By.xpath("//tbody/tr[1]/td[4]/a[1]")).click();



0

How to fetch all links

Webdriver driver=new FirefoxDriver();

driver.get("https://www.flipkart.com/");
List<WebElement>alllinks=driver.findElements(By.xpath("//a"));
int linkcount=alllinks.size();

for(int i=0;i<alllinks.size();i++){
String linkname=alllinks.get(i).getText();
System.out.println(linkname);
}


0

How to use Action class in selenium


Webdriver driver=new FirefoxDriver();
driver.get("https://www.yatra.com/");
Actions actions=new Actions(driver);
WebElement ele=driver.findElemet(By.xpath("//a[@class='dropdown-toggle eventTrackable']")
actions.moveToElement(ele).perform();
driver.findElement(By.linkText("Contact Us")).click();



0

How to check whether list is dropdown list or multiple select list


Webdriver driver=new FirefoxDriver();
driver.get("https://www.facebook.com/");
WebElement ele=driver.findElement(By.id("month"));
Select sel=new Select(ele);
if(sel.isMultiple()){
System.out.print("it is multiselect list box");
}
else{
System.out.print("it is dropdown box");
}


Output:it is dropdown box



0

How to Deselect options in Listbox


Webdriver driver=new FirefoxDriver();
driver.get("https://www.facebook.com/");
WebElement box=driver.findElement(By.id("month"));
Select sel=new Select(box);
sel.deselectbByValue("Jul");
sel.deselectByVisibleText("Aug");
sel.deselectByindex(5);
sel.deselectAll();
}

0

How to handle List box in selenium


WebDriver driver=new FirefoxDriver();
driver.get("https://www.facebook.com/");
WebElement box=driverfindElement(By.id("day"));
Select sel=new Select(box);
sel.SelectByIndex(1);
sel.SelectByVisibleText("Mar");
sel.SelectByValue("Oct");

0

program to print multiple multiplication table


int a,b,c.f;
Scanner in=new Scanner(System.in);
System.out.print("enter number");
a=in.nextInt();
b=in.nextInt();
for(c=a;c<=b;c++){
for(f=1;f<=10;f++){
System.out.println(c+"*"+f+"="+(c*f));
}


0

program to print multiplication table

int n,c;
int n=5;
for(c=1;c<=10;c++)
{
System.out.println(n+"*"+c+"="(n*c));

}

0

How to print all characters from a to z by using do whileloop


char c='A';
do{
System.out.print(c);
c++;
}while(c<='Z');


0

How to print all characters from a to z by using while loop



while(c<='Z');
char ch='a';
while(ch<=='z'){
System.out.print(ch);
ch++;
}}


0

How to print all characters from a to z by using for loop


char ch;
for(ch='a';ch<='z';ch++){
System.out.print(ch);
}


0

How to check whether checkbox is selected or not


WebDriver driver=new FirefoxDriver();
driver.get("http://www.ksrtc.in/oprs-web/");
WebElement chkbox=driver.findElement(By.name("singleLady"));
boolean selected=chkbox.isSelected();
if(selected==true){
System.out.print("Selected");
}else{
System.out.print("not selected");
box.click();
}



0

How to check whether radiobutton is selected or not


Webdriver driver=new FirefoxDriver();
driver.get("https://www.cleartrip.com/");
WebElement radio=driver.findElementBy.id("OneWay"));
boolean selected=radio.isselected();
if(selected==true){

System.out.print("already selected");
}
else{
System.out.print("not selected");
radio.click();

}




0

How to find tool tip text of web element

Webdriver driver=new FirefoxDriver();
driver.get("http://www.ksrtc.in/oprs-web/");
String ttext=driver.findElement(By.id("searchBtn")).getAttribute("title");
System.out.println(ttext);



0