You can get some examples for selenium web driver. Like File upload, Robot class, handle with alert, popup and File download- upload. It is also having basic for selenium web driver.
Sunday, 3 March 2013
Robot Example
Java code
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.util.Iterator;
import java.util.List;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class alert {
public static void main (String args[])
{
try
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.w3schools.com/js/tryit.asp?filename=tryjs_alert");
driver.switchTo().frame("viewIFRAME");
List<WebElement> input_buttons = driver.findElements(By.tagName("input"));
Iterator<WebElement> i = input_buttons.iterator();
while(i.hasNext())
{
WebElement _temp_input_button = i.next();
String str_type = _temp_input_button.getAttribute("type");
String str_value = _temp_input_button.getAttribute("value");
System.out.println("Type is :"+ str_type + " And Value is :"+str_value);
if ( str_type.trim().contentEquals("button") && str_value.trim().contentEquals("Show alert box"))
{
System.out.println("I am in block for clcik");
_temp_input_button.click();
call_Robot();
}
}
}
catch(Exception e)
{
System.out.println(e.fillInStackTrace().toString());
}
}
public static void call_Robot()
{
try {
Robot robot;
robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Note : I have used W3schools website for example purpose.
AutoIT Example : File Upload
Java Code :
import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class fileUpload2 {
public static void main (String args[])
{
try {
//Run AutoIT script through Java code
Runtime.getRuntime().exec("C:\\Users\\Desktop\\Senenium\\Fileupload.exe");
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Note : Used http://cgi-lib.berkeley.edu/ex/fup.html just for example
WebDriver driver=new FirefoxDriver();
driver.get("http://cgi-lib.berkeley.edu/ex/fup.html");
WebElement upload_btn = driver.findElement(By.name("upfile"));
upload_btn.click();
}
}
AutoIt v3 Script
Fileupload.au3
WinWaitActive("File Upload")
Send("C:\Users\Downloads\4.jpg")
Send("{Enter}");
Subscribe to:
Posts (Atom)