From 5a3258e56ffb8ace353636b3fba8c412048c2abb Mon Sep 17 00:00:00 2001 From: dadgam3er Date: Fri, 20 Sep 2024 10:58:37 -0400 Subject: [PATCH] linksCounts --- src/main/java/zacksolutions/Scope.java | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/main/java/zacksolutions/Scope.java diff --git a/src/main/java/zacksolutions/Scope.java b/src/main/java/zacksolutions/Scope.java new file mode 100644 index 0000000..c1b2f55 --- /dev/null +++ b/src/main/java/zacksolutions/Scope.java @@ -0,0 +1,65 @@ +package zacksolutions; + +import java.time.Duration; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +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.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Scope { + + public static WebDriver driver; + + public static void main(String[] args) throws InterruptedException { + Initialize(); + } + + public static void Initialize() throws InterruptedException { + System.setProperty("web-driver.gecko.driver", "user.dir" + "LearnSelenium/DemoProject/drivers/geckodriver"); + driver = new FirefoxDriver(); + driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5)); + String url = "https://qaclickacademy.com/practice.php"; + driver.get(url); + try { + linksCount(); + } finally { + driver.quit(); + } + } + + public static void linksCount() throws InterruptedException { + //all the links in the home page + List linkC = driver.findElements(By.tagName("a")); + System.out.println("The full page links count is: " + linkC.size()); + + //all links in the pageFooter + WebElement footdriver = driver.findElement(By.xpath("//div[@id='gf-BIG']")); + List footLinks = footdriver.findElements(By.tagName("a")); + System.out.println("The footer pages links amount to: " + footLinks.size()); + + //all the links in the first column + WebElement columnDriver = footdriver.findElement(By.xpath("//div/table/tbody/tr/td[1]/ul")); + List columnLinks = columnDriver.findElements(By.tagName("a")); + System.out.println("The column links amount to: " + columnLinks.size()); + + //Open each link in the column + for(int i = 1; i < columnLinks.size(); i ++){ + String clickON = Keys.chord(Keys.CONTROL, Keys.ENTER); + columnDriver.findElements(By.tagName("a")).get(i).sendKeys(clickON); + Thread.sleep(5000); + } + Set tabs = driver.getWindowHandles(); + Iterator it = tabs.iterator(); + while(it.hasNext()){ + driver.switchTo().window(it.next()); + System.out.println(driver.getTitle()); + } + } +}