Perform all the Operations on site: https://jqueryui.com/
- Draggable
- Droppable
- Resizable
- Selectable
- Sortable
- AutoComplete
- CheckBox Radio
- Control Group
- Date Picker
- Dialog
- Menu
- Select Menu
- Slider
- Spinner as Alert and Handling Enable and Disabled
- Tooltip
Autocomplete :
package widgets;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class autocomplete
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\Selenium Webdriver\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://jqueryui.com/slider/");
WebElement auto=driver.findElement(By.linkText("Autocomplete"));
auto.click();
WebElement text=driver.findElement(By.className("entry-title"));
String title=text.getText();
System.out.println(title);
driver.switchTo().frame(0);
WebElement textbox=driver.findElement(By.id("tags"));
Actions act=new Actions(driver);
act.click(textbox).sendKeys("Selenium").build().perform();
}
}
Button :
package widgets;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class autocomplete
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\Selenium Webdriver\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://jqueryui.com/slider/");
WebElement auto=driver.findElement(By.linkText("Autocomplete"));
auto.click();
WebElement text=driver.findElement(By.className("entry-title"));
String title=text.getText();
System.out.println(title);
driver.switchTo().frame(0);
WebElement textbox=driver.findElement(By.id("tags"));
Actions act=new Actions(driver);
act.click(textbox).sendKeys("Selenium").build().perform();
}
}
Button :
package widgets;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class Button
{
public static void main(String[] args)
{
System.setProperty(“webdriver.chrome.driver”, “C:\\Selenium Webdriver\\chromedriver.exe”);
WebDriver driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get(“http://jqueryui.com/slider/”);
WebElement button=driver.findElement(By.linkText(“Button”));
button.click();
WebElement title=driver.findElement(By.className(“entry-title”));
String text=title.getText();
System.out.println(text);
driver.switchTo().frame(0);
WebElement b1=driver.findElement(By.xpath(“/html/body/div/button”));
WebElement b2=driver.findElement(By.xpath(“/html/body/div/input”));
WebElement b3=driver.findElement(By.xpath(“/html/body/div/a”));
WebElement c1=driver.findElement(By.xpath(“/html/body/button”));
WebElement c2=driver.findElement(By.xpath(“/html/body/input”));
WebElement c3=driver.findElement(By.xpath(“/html/body/a”));
Actions act=new Actions(driver);
act.click(b1).build().perform();
act.click(b2).build().perform();
act.click(b3).build().perform();
act.click(c1).build().perform();
act.click(c2).build().perform();
act.click(c3).build().perform();
}
}
Checkbox :
package widgets;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class CheckBox
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\Selenium Webdriver\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://jqueryui.com/slider/");
WebElement clicklink=driver.findElement(By.linkText("Checkboxradio"));
clicklink.click();
driver.switchTo().frame(0);
WebElement select1=driver.findElement(By.xpath("/html/body/div/fieldset[1]/label[1]"));
WebElement check=driver.findElement(By.xpath("/html/body/div/fieldset[2]/label[4]/span[2]"));
//to check status of radio button
boolean status=driver.findElement(By.xpath("/html/body/div/fieldset[1]/label[1]")).isSelected();
System.out.println("Status of radio button is : "+status);
Actions act=new Actions(driver);
act.click(select1).build().perform();
act.click(check).build().perform();
}
}
Dialog :
package widgets;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class Dialog
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\Selenium Webdriver\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://jqueryui.com/slider/");
WebElement clickdate=driver.findElement(By.linkText("Dialog"));
clickdate.click();
driver.switchTo().frame(0);
WebElement box1=driver.findElement(By.id("ui-id-1"));
WebElement resize=driver.findElement(By.xpath("/html/body/div/div[3]"));
WebElement close=driver.findElement(By.xpath("/html/body/div/div[1]/button/span[1]"));
Actions act=new Actions(driver);
act.dragAndDropBy(box1, 70, 20).build().perform();
act.dragAndDropBy(resize, 0, 50).build().perform();
act.click(close).build().perform();
}
}
Menu :
package widgets;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class Menu
{
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\Selenium Webdriver\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://jqueryui.com/slider/");
WebElement clickdate=driver.findElement(By.linkText("Menu"));
clickdate.click();
driver.switchTo().frame(0);
WebElement book=driver.findElement(By.id("ui-id-2"));
WebElement clothing=driver.findElement(By.id("ui-id-3"));
WebElement electronics=driver.findElement(By.id("ui-id-4"));
Thread.sleep(500);
WebElement utility=driver.findElement(By.id("ui-id-7"));
WebElement music=driver.findElement(By.id("ui-id-9"));
WebElement musicrock=driver.findElement(By.id("ui-id-10"));
//WebElement musicrockClassic=driver.findElement(By.id("ui-id-12"));
Actions act=new Actions(driver);
act.click(book).build().perform();
act.click(clothing).build().perform();
act.click(electronics).build().perform();
act.click(utility).build().perform();
act.click(music).build().perform();
act.click(musicrock).build().perform();
//act.click(musicrockClassic).build().perform();
}
}
ControlGroup :
package widgets;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
public class ControlGroup
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\Selenium Webdriver\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://jqueryui.com/slider/");
WebElement clickcontrol=driver.findElement(By.linkText("Controlgroup"));
clickcontrol.click();
driver.switchTo().frame(0);
WebElement compactcar=driver.findElement(By.id("car-type-button"));
WebElement dropdwn1=driver.findElement(By.id("ui-id-4"));
WebElement radio1=driver.findElement(By.xpath("/html/body/div[1]/fieldset[1]/div/label[1]"));
WebElement checkbx=driver.findElement(By.xpath("/html/body/div[1]/fieldset[1]/div/label[3]"));
WebElement noOfcar=driver.findElement(By.xpath("//input[@class='ui-spinner-input' and @id='horizontal-spinner']"));
noOfcar.sendKeys("5");
WebElement booking=driver.findElement(By.xpath("/html/body/div[1]/fieldset[1]/div/button"));
WebElement compactcar1=driver.findElement(By.xpath("//*[@id=\"ui-id-8-button\"]/span[2]"));
WebElement dropdwn2=driver.findElement(By.id("ui-id-11"));
WebElement radio2=driver.findElement(By.xpath("/html/body/div[1]/fieldset[2]/div/label[1]"));
WebElement checkbx2=driver.findElement(By.xpath("/html/body/div[1]/fieldset[2]/div/label[2]"));
/*Select noOfcar2=new Select(driver.findElement(By.xpath("/html/body/div[1]/fieldset[1]/div/span[2]/a[1]/span[1]")));
noOfcar2.selectByIndex(4);*/
WebElement booking2=driver.findElement(By.id("book"));
Actions act=new Actions(driver);
act.click(compactcar).build().perform();
act.click(dropdwn1).build().perform();
act.click(radio1).build().perform();
act.click(checkbx).build().perform();
act.click(noOfcar).build().perform();
act.click(booking).build().perform();
act.click(compactcar1).build().perform();
act.click(dropdwn2).build().perform();
act.click(radio2).build().perform();
act.click(checkbx2).build().perform();
//act.click((WebElement) noOfcar2).build().perform();
act.click(booking2).build().perform();
}
}
Spinner :
package widgets;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class Spinner
{
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\\Selenium Webdriver\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://jqueryui.com/slider/");
WebElement clickdate=driver.findElement(By.linkText("Spinner"));
clickdate.click();
driver.switchTo().frame(0);
WebElement select=driver.findElement(By.xpath("/html/body/p[1]/span/a[1]/span[1]"));
WebElement select5=driver.findElement(By.id("setvalue"));
Thread.sleep(200);
WebElement getvalue=driver.findElement(By.id("getvalue"));
/*//switching to alerts
Alert alert=driver.switchTo().alert();
//get alert message
String alertmsg=driver.switchTo().alert().getText();
//display alrt msg
System.out.println(alertmsg);
Thread.sleep(500);
//accepting alrt
alert.accept();*/
Actions act=new Actions(driver);
act.click(select).build().perform();
act.click(select5).build().perform();
act.click(getvalue).build().perform();
}
}
Tabs :
package widgets;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class Tabs
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\Selenium Webdriver\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://jqueryui.com/slider/");
WebElement clickdate=driver.findElement(By.linkText("Tabs"));
clickdate.click();
driver.switchTo().frame(0);
WebElement proinTab=driver.findElement(By.id("ui-id-2"));
WebElement aneanTab=driver.findElement(By.id("ui-id-3"));
Actions act=new Actions(driver);
act.click(proinTab).build().perform();
act.click(aneanTab).build().perform();
}
}
1.Droppable :
Actions act=new Actions(driver); //create the action object
driver.get("http://jqueryui.com/droppable/"); //open the url
driver.switchTo().frame(0); //switching the frame from one frame to another
WebElement source= driver.findElement(By.xpath("//*[@id='draggable']")); //xpath of draggable
WebElement target=driver.findElement(By.xpath("//*[@id='droppable']")); //xpath of droppable
//act.contextClick(source); //right click mouse action
Thread.sleep(3000);
act.dragAndDrop(source, target).perform();//executing action object
Thread.sleep(4000);
driver.quit();