0% found this document useful (0 votes)
80 views

Module 2 - Assignment

Uploaded by

priyanka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views

Module 2 - Assignment

Uploaded by

priyanka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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