Posts

Showing posts from 2017

How to upload image using sikuli

Though webdriver handles the file uploading smartly but there are some time when you need to work with external tools such as AutoIT, again AutoIT doesn't go good with linux system hence we may use sikuli to upload the image. Click on link which will populate the file upload dialog, and take printscreen for Fileupload area and open button and save them in some location. Pattern fileLoad = new Pattern("{yourPath}/FileLoadInput.png"); Pattern openButton = new Pattern("{yourPath}/openButton.png"); Screen src = new Screen(); src.setAutoWaitTimeout(30); // Clear the input field if any is selected by default. src.type("a", Key.CTRL); src.type(Key.BACKSPACE); //Type in input filed name of the image and click on open button src.type(fileLoad, sFileName); src.click(openButton);

Comparing sum of string's digit by splitting string in 2 halfs

import java.util.Scanner; public class Lottry { static boolean bLot = false; public static void main(String[] args) { Scanner sc = new Scanner(System.in); String sNum = sc.next(); if(blottry(sNum)){ System.out.println("Won the lottry"); }else{ System.out.println("Not won the lottry"); } sc.close(); } static boolean blottry(String s){ int sum1 = 0; int sum2 = 0; char[]cLot = s.toCharArray(); System.out.println("Lenght of String digit::"+ cLot.length); if(cLot.length>=4 && cLot.length%2==0){ for(int i = 0; i<cLot.length/2; i++){ sum1 = sum1 + Character.getNumericValue(cLot[i]); } System.out.println("Sum1:::::::::::::::"+ sum1); for(int i=cLot.length-1; i >= cLot.length/2; i--){ sum2 = sum2 + Character.getNumericValue(cLot[i]); } System.out.println("Sum2:::::::::::::::"+ sum2); } if(sum1==sum2){ ...

Parsing xml node tags using documentbuilderfactory

package test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.NodeList; public class xmlTest { public static void main(String[] args) throws Exception { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.parse("filePath"); NodeList nlist = doc.getElementsByTagName("param"); System.out.println(nlist.getLength()); for(int ent=0; ent<nlist.getLength(); ent++){ System.out.println(doc.getElementsByTagName("param").item(ent).getTextContent()); } } }