moreLocators
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 9s
Gitea Actions Demo / mvnSelBuild (push) Failing after 49s

This commit is contained in:
dadgam3er 2024-09-18 03:06:04 -04:00
parent 40af12f5dc
commit fcc3e156b4
3 changed files with 104 additions and 41 deletions

BIN
screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -0,0 +1,50 @@
package zacksolutions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.lang.reflect.Array;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
public class AmazonQuestion {
public static WebDriver driver;
public static String[] items = { "Brocolli", "Beetroot", "Beans", "Carrot", "Potato" };
public static void main(String[] args) throws InterruptedException {
System.setProperty("web-driver.gecko.driver", "/home/ilyes/LearnSelenium/DemoProject/drivers/geckodriver");
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
String url = "https://rahulshettyacademy.com/seleniumPractise/";
driver.get(url);
Thread.sleep(3000);
try {
getItems();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
driver.close();
}
}
public static void getItems() throws InterruptedException {
List<WebElement> itemsName = driver.findElements(By.cssSelector("h4[class$='product-name']"));
List<String> listOfItems = Arrays.asList(items);
int lastItem = 0;
for (int i = 0; i < itemsName.size(); i++) {
String item = itemsName.get(i).getText().split(" - ")[0].trim();
if (listOfItems.contains(item)) {
driver.findElements(By.xpath("//div[@class='product-action']/button")).get(i).click();
lastItem++;
if (lastItem == listOfItems.size()) {
break;
}
}
}
}
}

View File

@ -1,53 +1,66 @@
package zacksolutions;
import org.apache.maven.surefire.shared.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.io.File;
import java.io.IOException;
import java.time.Duration;
public class Locators {
public static void main(String[] args) throws InterruptedException {
Locators lc = new Locators();
lc.loginPage();
}
public static WebDriver driver;
public void loginPage() throws InterruptedException {
System.setProperty("web-driver.gecko.driver", "/home/ilyes/LearnSelenium/DemoProject/drivers/geckodriver");
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
String url = "https://rahulshettyacademy.com/locatorspractice/";
driver.get(url);
driver.findElement(By.cssSelector("input[id='inputUsername']")).sendKeys("Zakaria");
driver.findElement(By.cssSelector("input[name='inputPassword']")).sendKeys("Zakaria");
driver.findElement(By.cssSelector("button[type='submit']")).click();
String Err = driver.findElement(By.cssSelector("p.error")).getText();
System.out.println(Err);
driver.findElement(By.linkText("Forgot your password?")).click();
driver.findElement(By.xpath("//input[@placeholder='Name']")).sendKeys("Desmond");
driver.findElement(By.xpath("//input[@placeholder='Email']")).sendKeys("hdesmond@island.con");
driver.findElement(By.cssSelector("input[placeholder='Phone Number']")).sendKeys("5551118888");
Thread.sleep(1000);
driver.findElement(By.cssSelector(".reset-pwd-btn")).click();
System.out.println("");
String newUser = driver.findElement(By.cssSelector("form p")).getText();
System.out.println(newUser);
String passw = "rahulshettyacademy";
System.out.println("New User Created please enter the password: " + passw);
Thread.sleep(1000);
driver.findElement(By.cssSelector(".go-to-login-btn")).click();
Thread.sleep(1000);
driver.findElement(By.cssSelector("input[id='inputUsername']")).sendKeys("Desmond");
driver.findElement(By.cssSelector("input[placeholder='Password']")).sendKeys(passw);
driver.findElement(By.xpath("//input[@id='chkboxOne']")).click();
driver.findElement(By.xpath("//input[@id='chkboxTwo']")).click();
driver.findElement(By.cssSelector("button[type='submit']")).click();
Thread.sleep(1000);
String homePage = driver.getTitle();
System.out.println(homePage);
public static void main(String[] args) throws InterruptedException, IOException {
Locators lc = new Locators();
lc.loginPage();
Thread.sleep(2000);
driver.close();
getScreenShot(driver);
}
}
}
public void loginPage() throws InterruptedException {
System.setProperty("web-driver.gecko.driver", "/home/ilyes/LearnSelenium/DemoProject/drivers/geckodriver");
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
String url = "https://rahulshettyacademy.com/locatorspractice/";
driver.get(url);
driver.findElement(By.cssSelector("input[id='inputUsername']")).sendKeys("Zakaria");
driver.findElement(By.cssSelector("input[name='inputPassword']")).sendKeys("Zakaria");
driver.findElement(By.cssSelector("button[type='submit']")).click();
String Err = driver.findElement(By.cssSelector("p.error")).getText();
System.out.println(Err);
driver.findElement(By.linkText("Forgot your password?")).click();
driver.findElement(By.xpath("//input[@placeholder='Name']")).sendKeys("Desmond");
driver.findElement(By.xpath("//input[@placeholder='Email']")).sendKeys("hdesmond@island.con");
driver.findElement(By.cssSelector("input[placeholder='Phone Number']")).sendKeys("5551118888");
Thread.sleep(1000);
driver.findElement(By.cssSelector(".reset-pwd-btn")).click();
System.out.println("");
String newUser = driver.findElement(By.cssSelector("form p")).getText();
System.out.println(newUser);
String passw = "rahulshettyacademy";
System.out.println("New User Created please enter the password: " + passw);
Thread.sleep(1000);
driver.findElement(By.cssSelector(".go-to-login-btn")).click();
Thread.sleep(1000);
driver.findElement(By.cssSelector("input[id='inputUsername']")).sendKeys("Desmond");
driver.findElement(By.cssSelector("input[placeholder='Password']")).sendKeys(passw);
driver.findElement(By.xpath("//input[@id='chkboxOne']")).click();
driver.findElement(By.xpath("//input[@id='chkboxTwo']")).click();
driver.findElement(By.cssSelector("button[type='submit']")).click();
Thread.sleep(1000);
String homePage = driver.getTitle();
System.out.println(homePage);
Thread.sleep(2000);
}
public static void getScreenShot(WebDriver driver) throws IOException {
File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new File("/home/ilyes/SeleniumPractice/SeleniumIntro/screenshot.png"));
System.out.println("Picture taken... Please check your forlder");
driver.close();
}
}