public List<WebElement> findElementsByXPath(String using) { return findElements("selectElementsUsingXPath", using); }
public List<WebElement> findElementsById(String using) { return findElements("selectElementsUsingId", using); }
public List<WebElement> findElementsByLinkText(String using) { return findElements("selectElementsUsingLink", using); }
public List<WebElement> findElementsByName(String using) { return findElements("selectElementsUsingName", using); }
public List<WebElement> findElementsByPartialLinkText(String using) { return findElements("selectElementsUsingPartialLinkText", using); }
public List<WebElement> findElementsByTagName(String using) { return findElements("selectElementsUsingTagName", using); }
List<WebElement> listAllRadioButtons= driver.findElements(By.cssSelector("input[type='radio']")); List<WebElement> listAllRadioButtonsChecked= driver.findElements(By.cssSelector("input[type='radio']:checked")); List<WebElement> listAllRadioButtonsFromTable = driver.findElements(By.cssSelector("table>tbody>tr>td>input[type='radio']")); List<WebElement> listAllRadioButtonsFromTableChecked = driver.findElements(By.cssSelector("table>tbody>tr>td>input[type='radio']:checked")); List<WebElement> listCol = driver.findElements(By.cssSelector("table>tbody>tr>td:nth-child("+colNumber+")")); List<WebElement> listColRadioButton = driver.findElements(By.cssSelector("table>tbody>tr>td:nth-child("+colNumber+")>input[type='radio']")); List<WebElement> listColRadioButtonChecked = driver.findElements(By.cssSelector("table>tbody>tr>td:nth-child("+colNumber+")>input[type='radio']:checked")); List<WebElement> listRowRadioButton = driver.findElements(By.cssSelector("table>tbody>tr:nth-child("+rowNumber+")>td>input[type='radio']")); List<WebElement> listRowRadioButtonChecked = driver.findElements(By.cssSelector("table>tbody>tr:nth-child("+rowNumber+")>td>input[type='radio']:checked"));
public List<WebElement> findElementsByClassName(String using) { if (using == null) throw new IllegalArgumentException("Cannot find elements when the class name expression is null."); if (using.matches(".*\\s+.*")) { throw new IllegalLocatorException( "Compound class names are not supported. Consider searching for one class name and filtering the results."); } return findElements("selectElementsUsingClassName", using); }
FirefoxDriver driver = new FirefoxDriver(); driver.get("https://www.google.com"); List<WebElement> links = driver.findElements(By.cssSelector("#gbw a.gb_P")); for (WebElement link : links) { System.out.println(link.getText().trim()); }
FirefoxDriver driver = new FirefoxDriver(); driver.get("https://www.youtube.com/watch?v=JcbBNpYkuW4"); WebElement element = driver.findElementByCssSelector("#watch-discussion"); System.out.println(element.getText()); // this prints: loading.. // scrolll down so that comments start to load driver.executeScript("window.scrollBy(0,500)", ""); Thread.sleep(20000); List<WebElement> iframes = driver.findElements(By.xpath("//iframe")); for(WebElement e : iframes) { if(e.getAttribute("id") != null && e.getAttribute("id").startsWith("I0_")) { // switch to iframe which contains comments driver.switchTo().frame(e); break; } } // fetch all comments List<WebElement> comments = driver.findElements(By.xpath("//div[@class='Ct']")); for(WebElement e : comments) { System.out.println(e.getText()); }