Module 2_Assignment

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Selenium Module 2

Assignment Submitted By-Priyanka Yadav(26 May Weekday Batch)

Assignment -1(WebTable):

➤ url : https://demo.guru99.com/test/web-table-element.php

➤ Retrieve the all company names from the table

➤ And display in console

package Module2;

import java.util.List;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

public class Assignment1 {

public static void main(String[] args) {

WebDriver driver= new ChromeDriver();

driver.get("https://demo.guru99.com/test/web-table-element.php");

List <WebElement> row =


driver.findElements(By.xpath(".//*[@id='leftcontainer']/table/tbody/tr/td[1]"));

System.out.println("No of rows are : " + row.size());

for(WebElement name:row)

System.out.println("Company names " + name.getText());

}
driver.close();

➤ url : https://demo.guru99.com/test/login.html

➤ Enter email

➤ Enter password

➤ Click on Login button

package Module2;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class Assignment1_Login {

public static void main(String[] args) {

WebDriver driver =new ChromeDriver();

driver .get("https://demo.guru99.com/test/login.html");

driver.findElement(By.xpath("//input[@id=\"email\"]")).sendKeys("Admin");

driver.findElement(By.name("passwd")).sendKeys("admin123");

driver.findElement(By.name("SubmitLogin")).click();

Assignment -2(Handling Alerts, Frames, Windows):

➤https://demo.guru99.com/test/delete_customer.php

➤ Enter customer Id
➤ Click on Submit

➤ One prompt will open click on ok

➤ Again open one prompt click on ok

Reference site : https://www.guru99.com/alert-popup-handling-selenium.html

package Module2;

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;

public class Assignment2 {

public static void main(String[] args) throws InterruptedException {

WebDriver driver= new ChromeDriver();

driver.manage().window().maximize();

driver.get("https://demo.guru99.com/test/delete_customer.php");

Thread.sleep(1000);

driver.findElement(By.name("cusid")).sendKeys("C_01");

driver.findElement(By.name("submit")).click();

Thread.sleep(1000);

Alert alerts = driver.switchTo().alert();

System.out.println(alerts.getText());

Thread.sleep(1000);

alerts.accept();

//second alert
System.out.println(alerts.getText());

Thread.sleep(1000);

alerts.accept();

driver.close();

Assignment -2.1(Frames):

➤https://demo.guru99.com/test/delete_customer.php

➤ Click on the frame shown in the image

package Module2;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class Assignment2_1 {

public static void main(String[] args) throws InterruptedException {

WebDriver driver= new ChromeDriver();

driver.get("https://demo.guru99.com/test/guru99home/");

driver.manage().window().maximize();

driver.switchTo().frame("a077aa5e");

Thread.sleep(3000);
driver.findElement(By.xpath("html/body/a/img")).click();

Reference site : https://www.guru99.com/handling-iframes-selenium.html

Assignment -2.2(Windows):

➤url : http://demo.guru99.com/popup.php

➤ Click on Click here

➤ It will go to next window. Then enter Email Id

➤ Click on Submit

package Module2;

import java.util.Iterator;

import java.util.Set;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class Assignment2_2 {

public static void main(String[] args) {

WebDriver driver= new ChromeDriver();

driver.get("https://demo.guru99.com/popup.php");

driver.findElement(By.linkText("Click Here")).click();

String parent=driver.getWindowHandle();

Set <String> handles= driver.getWindowHandles();

Iterator<String> it=handles.iterator();

while(it.hasNext())
{

String Child_window=it.next();

if(!parent.equals(Child_window))

driver.switchTo().window(Child_window);

driver.findElement(By.name("emailid")).sendKeys("admin@123");

driver.findElement(By.name("btnLogin")).click();

driver.close();

driver.switchTo().window(parent);

Assignment -3(Actions, JavaScript Executors):

➤url : https://jqueryui.com/

➤ Click on Draggable

➤ Drag the “Drag me around” box another place

➤ Take the Screeshot of that dragged

➤ Suggested method javascript Executor

package Module2;

import java.io.File;

import java.io.IOException;

import org.openqa.selenium.By;

import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.interactions.Action;

import org.openqa.selenium.interactions.Actions;

import org.openqa.selenium.io.FileHandler;

public class Assignment3 {

static WebDriver driver;

public static void main(String[] args) throws IOException {

driver= new ChromeDriver();

driver.manage().window().maximize();

driver.get("https://jqueryui.com/");

driver.findElement(By.linkText("Draggable")).click();

WebElement frames= driver.findElement(By.xpath("//iframe[@class='demo-frame']"));

driver.switchTo().frame(frames);

Actions act = new Actions(driver);

WebElement source = driver.findElement(By.id("draggable"));

act.moveToElement(source).clickAndHold().moveByOffset(100, 100).perform();

captureScreenshot("Drag");

driver.close();

//screenshot

public static void captureScreenshot(String tcname) throws IOException {


TakesScreenshot ts = (TakesScreenshot) driver;

File scrnshot = ts.getScreenshotAs(OutputType.FILE);

String filePath = "./Screenshots/" + tcname + ".png";

FileHandler.copy(scrnshot, new File(filePath));

You might also like