Sunday 29 March 2015

HTML & Web Driver

Enter the data in HTML editior through selenumn web driver-
1.Below is the html code for understanding :-
 <iframe id="message_ifr" frameborder="0" allowtransparency="true" title="Rich Text Area. Press ALT-F9 for menu. Press ALT-F10 for toolbar. Press ALT-0 for help" style="width: 100%; height: 100px; display: block;" src="javascript:""">
<!DOCTYPE html>
<html>
<head>
<style id="mceDefaultStyles" type="text/css">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<link href="http://cgpdigitallibrary.com/www/js/tinymce/skins/lightgray/content.min.css" rel="stylesheet" type="text/css">
</head>
<body id="tinymce" class="mce-content-body " contenteditable="true" data-id="message" spellcheck="false">
<p>
<br data-mce-bogus="1">
</p>
</body>
</html>
</iframe>
2.Web driver code for to switch in to iframe and enter the data in html box

driver.switchTo().frame("message_ifr");  // this line for switching in to iframe
WebElement element = driver.findElement(By.id("tinymce"));// in iframe search the particular id
System.out.println("Entering something in text input");//For debugging purpose
element.sendKeys(Keys.CONTROL + "a");//for whole text for input
element.sendKeys("note for user famcom");// type in to free text box
driver.switchTo().defaultContent();// it is necessary to move out from html editor to perform new task



Monday 23 March 2015

How to upload the file using selenium web driver except type the url in send key or autoit

How to upload the file using selenium web driver except type the url in send key or autoit

I have used robot class(generate native system input events)
it is used to take the control of mouse and keyboard event.
Once you get the control, you can do any type of operation related to mouse and keyboard through with java code.
Below example I have used 'keyPress' and 'keyRelease' methods with description.

keyPress - Takes keyCode as Parameter and Presses here a given key.
keyrelease - Takes keyCode as Parameterand Releases a given key.
package automationFramework;.

import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class fileupload {

    String URL = "http://convertonlinefree.com/PDFToWORDEN.aspx";
    WebDriver driver;
    @Test
    public void testUpload() throws InterruptedException
    {
        System.setProperty("webdriver.chrome.driver", "D:\\AutomationPHP\\chromedriver_win32\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.get(URL);
        driver.manage().window().maximize();
        WebElement element = driver.findElement(By.xpath("//*[@id='MainContent_fuDOCX']"));
        element.click();
        uploadFile("C:\\Users\\Administrator\\Desktop\\UCLA - Copy.pdf");
        Thread.sleep(2000);
    }
   
    /*
      This method will set any parameter string to the system's fileupload box.
     */
    public static void setClipboardData(String string) {
        //Class used for copy and paste operations -StringSelection
        System.out.println(string);
           StringSelection stringSelection = new StringSelection(string);
           Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
        }
   
    public static void uploadFile(String fileLocation) {
        try {
            // file location set with file dialogue box
            setClipboardData(fileLocation);
            //CTRL, V and ENTER keys for native key strokes
            Robot robot = new Robot();
   
            robot.keyPress(KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_V);
            robot.keyRelease(KeyEvent.VK_V);
            robot.keyRelease(KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_ENTER);
            robot.keyRelease(KeyEvent.VK_ENTER);
        } catch (Exception exp) {
            exp.printStackTrace();
        }
    }
}


Donate:

Please Donate the some money (anything do you want) for my
blog if you beneficial for this, I will provide more real example for the
latest technique for whom who wants to make a carrier in IT field or solved
some problem, My Name is – RITESH KUMAR SINGH A/C number- 913010044116345 AXIS
Bank LTD :- Vaishali NCR, India-001
 


How to search the value in grid and delete the particular record in selenumn web driver

How to search the value in grid and delete the particular record in selenumn web driver

Below is the code to search the particular record in grid through xpath manuplation

Step-1. First you need to divide the xpath in two part, store in two different string object
2.Full xpath like  below
  //*[@id='rup_data_binding_tr_0_search_form_list']/td[2]/p
3.We need to search the 

            String xp1="//*[@id='rup_data_binding_tr_"+i;
            String xp2="_search_form_list']/td[2]/p";
            for (int i=0;i<12;i++)
            {
                WebElement gettext=driver.findElement(By.xpath(xp1.concat(xp2)));
                System.out.println("all agency ="+gettext.getText());
                if (text.equals(gettext.getText()))
                {
                           System.out.println("Deleted Agency ="+gettext.getText());
                           Assert.assertEquals(text,gettext.getText());
                          driver.findElement(By.xpath(xp1.concat("_search_form_list']/td[8]/p/a[2]  
                         /img"))).click();
                         driver.findElement(By.xpath("//*[@id='dvRupConfirmBox']/div[2]  
                         /input[2]")).click();
                          break;
                }
            }

Thursday 19 March 2015

How to invoke Chrome driver using with chrome driver

How to invoke Chrome driver using with chrome driver

Step 1- Please go the http://docs.seleniumhq.org/download/ section and download the
latest chrome driver from Third party browser, direct link is http://chromedriver.storage.googleapis.com/index.html?path=2.14/

Step 2 : Put the driver exe in your project folder

Step 3: Give the exe path to below function

System.setProperty("webdriver.chrome.driver", "D:\\AutomationPHP\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();

Step 4:- Now you can use chrome browser with your script, Please download correct driver for particular platform or 32 bit or 64 bit



Donate:

Please Donate the some money (anything do you want) for my
blog if you beneficial for this, I will provide more real example for the
latest technique for whom who wants to make a carrier in IT field or solved
some problem, My Name is – RITESH KUMAR SINGH A/C number- 913010044116345 AXIS
Bank LTD :- Vaishali NCR, India-001