Commit b46d1fa8 authored by Qazi Zain's avatar Qazi Zain

Actions updated and ChildWindowHandling code added

parent 16a1ab58
package Techniques.Actions;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.asserts.SoftAssert;
import java.time.Duration;
public class ActionsMethods {
public static void main(String[] args) {
WebDriver obj = new FirefoxDriver();
obj.get("https://www.amazon.com/");
//Creating Action Class.
Actions mouse = new Actions(obj);
// Wait used for create explicit wait.
WebDriverWait wait = new WebDriverWait(obj, Duration.ofSeconds(5));
obj.manage().window().maximize();
// creating web Element.
WebElement locator= obj.findElement(By.id("nav-link-accountList"));
WebElement navbar = wait.until(ExpectedConditions.elementToBeClickable(locator));
mouse.moveToElement(navbar).build().perform();
//Creating WebElement
WebElement search= obj.findElement(By.id("twotabsearchtextbox"));
// passing key in capital letter.
wait.until(ExpectedConditions.elementToBeClickable(search));
mouse.moveToElement(search).click().keyDown(Keys.SHIFT).sendKeys("Hello").doubleClick().build().perform();
// scrolling dowwn.
mouse.scrollByAmount(0,4000).perform(); // will scroll down 600px.
// String values= obj.findElement(By.xpath("//div[@id='CardInstanceSJR_RNu0KrfMtMjmIWfcTw']/div/div/h2/span")).getText();
// System.out.println("The Value present at there is: "+values);
SoftAssert softassert = new SoftAssert();
softassert.assertEquals("hi kazi","ho");
mouse.scrollByAmount(0,-4000).perform();
softassert.assertAll(); // it will scroll up 300px.
}
}
package Techniques.ChildWindowHandling;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class ChildWindow
{
public static void main(String[] args)
{
WebDriver obj = new FirefoxDriver();
obj.get("https://rahulshettyacademy.com/loginpagePractise/#");
obj.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
WebElement Link = obj.findElement(By.className("blinkingText"));
Link.click();
// now use window methods.
//create set.
HashSet<String> windows = new HashSet<>(obj.getWindowHandles());
Iterator<String> it = windows.iterator(); // set iterator on window.
String parentWindow= it.next();
String childWindow= it.next();
// now switch to child window.
obj.switchTo().window(childWindow);
WebDriverWait wait = new WebDriverWait(obj, Duration.ofSeconds(5));
WebElement paragraph = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("p.im-para.red")));
String email = paragraph.getText();
obj.switchTo().window(parentWindow);
WebElement emailBox = obj.findElement(By.id("username"));
String []emailFinal = email.split(" ");
emailFinal[4].trim();
emailBox.sendKeys(emailFinal[4]);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment