Posts

Selenium-Revision

What is Parent Child in Xpath…? Ex1:   //div[@class='abc']/div/div[2]/input Ex where to use parent child… Assume a HTML tag does not contains any attributes(ex: name or class or id) to identify in such cases user has to use traverse method in xpath i.e parent child. Ex2: in Above example parent tag is continuing till child class. '          Where as in below example from the parent Tag its looking for child Tag, this I the another best example. //div[@id='glsctl00_mainContent_ddl_originStation1_CTNR'] //a[@value='MAA'] ChroPath is used in Chrome which same as like Firpath in Firefox. Difference between Relative and Absolute xpath.? Relative: Relative doesn't depend on the Parent class. Ex: //*[@name='q'] Absolute: Parent to child Ex: //div[@class='abc']/div/div[2]/input How to traverse to siblings elements using xpath. ? Ex: //div[@class='abc']/following-siblling::li[1] Sibling ex

Handling Excel

Read Excel: package excelExportAndFileIO; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; public class ReadExcelFile { public void readExcel(String filePath,String fileName,String sheetName) throws IOException{     //Create a object of File class to open xlsx file     File file =    new File(filePath+"\\"+fileName);     //Create an object of FileInputStream class to read excel file     FileInputStream inputStream = new FileInputStream(file);     Workbook Workbook = null;     //Find the file extension by spliting file name in substring and getting only extension name     String fileExtensionName = fileName.substring(fileName.indexOf("."));     //Check condition if the file is xls

Selenium Programs

AddToCardBigBasket: public class AddToCardBigBasket { WebDriver driver; @Test void addToCart() throws InterruptedException{ System.setProperty("webdriver.chrome.driver", "C:\\Automation\\Selenium\\drivers\\chromedriver_win32\\chromedriver.exe"); driver = new ChromeDriver(); driver.get("https://www.bigbasket.com/ps/?q=vegetables"); String[] vegetables = {"Tomato - Hybrid","Parwal"}; List vegetablesList = driver.findElements(By.xpath("//div[@qa='product_name']//a[@class='ng-binding']")); for(int i=0;i List vegList = Arrays.asList(vegetables); //System.out.println(vegList); if(vegList.contains(vegetablesList.get(i).getText())) { System.out.println("found : " + vegetablesList.get(i).getText()); String elements = "//a[text()='"+vegetablesList.get(i).getText()+"']/parent::div[@class='col-sm-12 col-xs-7 p

Collections and DBConnections and Grid

HashMap: public class CollectionsHashMap { public static void main(String[] args) { // TODO Auto-generated method stub HashMap hs = new HashMap (); HashMap hsNew = new HashMap (); hs.put(3, "Gaddam"); hs.put(1, "Santosh"); hs.put(2, "kumar"); System.out.println(hs); System.out.println("==="); hs.remove(2); System.out.println(hs); System.out.println("==="); hs.put(3, "Gaddams"); hs.put(4, ""); hs.put(5, ""); hs.put(null, "its me null key"); hs.put(null, "its me null keys"); System.out.println(hs); Set hp = hs.entrySet(); Iterator ip = hp.iterator(); while(ip.hasNext()) { Map.Entry mp = (Map.Entry)ip.next(); System.out.println(mp.getKey() + " " +mp.getValue()); } // practise purpose HashMap hm = new HashMap (); hm.put(1, "Selenium"); hm.put(2, "QTP");

JavaInterviewPrograms

Find a letter or String in a String: String a = "santosh kumar Gaddam"; a.length();                 System.out.println(a.contains("kumar")); // find a word from given string using in-build method for(int i=0; i if(a.charAt(i) == 'n') { System.out.println("found n at : " + i); //find a letter break; //break the for loop } } //Find a number in Array int a[] = {1,2,3,4,5}; int find = 4; for(int i=0; i if(a[i]==find){ System.out.println("number found"); System.out.println("position of the number is : "+i); break; } else { System.out.println("not found at : " + i); } } //Find a Large number from an array. int a[] = {10,1,3,8,50}; int large=a[0]; for(int i=0; i if(a[i]>large) { large = a[i]; } }                 System.out.println("large number is : "+large); //Find a Low/Minimum number from an array int a[] = {10,1,3,8,50}; int low