MULTIPLE ELEMENTS
. Web driver provides a method find element which can be used to find multiple elements based on the element locator
To find all the link in page
If we have inages with the link its print spaces
GET ALL LINKS |
Package mypackage;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class GetAllLinks{
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver","C:\\Browser\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("https://www.amazon.in/");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
List<WebElement> alllinks=driver.findElements(By.xpath("//html[@data-19ax5a9jf='dingo']"));
int si=alllinks.size();
for (int i = 0; i < si; i++) {
WebElement link=alllinks.get(i);
String al=link.getText();
System.out.println(al);
driver.quit();
}
}
}
ALL CHECK BOKES |
package mypackage;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AllCheckBoxes {
public static void main(String[] args) {
System.setProperties("webDriver.gecko.driver","c:\\ram\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.seleniumeasy.com/test/basic-checkbox-demo.html");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
List<WebElement> allcheckbox=driver.findElements(By.xpath("//input[@type='checkbox']"));
int si=allcheckbox.size();
for (int i = 0; i < si; i++) {
WebElement check=allcheckbox.get(i);
check.click();
}
}
}