How to use findElements method of org.openqa.selenium.Interface WebElement class

Best Selenium code snippet using org.openqa.selenium.Interface WebElement.findElements

Source:JavaIEWebElement.java Github

copy

Full Screen

...82 {83 return by.findElement(this);84 }85 @Override86 public List<WebElement> findElements(By by)87 {88 return by.findElements(this);89 }90 @Override91 public String getAttribute(String attr)92 {93 String value = null;94 if ("index".equals(attr))95 {96 IHTMLOptionElement option = watijElem.queryInterface(IHTMLOptionElement.class);97 value = Integer.toString(option.index());98 }99 else if ("text".equals(attr))100 {101 value = watijElem.innerText();102 }103 else if ("value".equals(attr))104 {105 if ("OPTION".equalsIgnoreCase(watijElem.tagName()))106 {107 value = watijElem.queryInterface(IHTMLOptionElement.class).value();108 }109 else if ("INPUT".equalsIgnoreCase(watijElem.tagName()))110 {111 watijElem.queryInterface(IHTMLInputElement.class).value();112 }113 }114 else115 {116 value = watijElem.getAttribute(attr, RETURN_AS_BSTR).toString();117 }118 return value;119 }120 @Override121 public String getCssValue(String cssAttr)122 {123 return watijElem.style().getAttribute(cssAttr, RETURN_AS_BSTR).toString();124 }125 @Override126 public Point getLocation()127 {128 IHTMLElement2 elem2 = watijElem.queryInterface(IHTMLElement2.class);129 IHTMLRect bounds = elem2.getBoundingClientRect();130 return new Point(bounds.left(), bounds.top());131 }132 @Override133 public Dimension getSize()134 {135 IHTMLElement2 elem2 = watijElem.queryInterface(IHTMLElement2.class);136 IHTMLRect bounds = elem2.getBoundingClientRect();137 return new Dimension(bounds.right() - bounds.left(), bounds.bottom() - bounds.top());138 }139 @Override140 public String getTagName()141 {142 return watijElem.tagName();143 }144 @Override145 public String getText()146 {147 return watijElem.innerText();148 }149 protected boolean isVisible(IHTMLElement elem)150 {151 if (elem.style() != null && HIDDEN_VISIBLE_STYLE.equals(elem.style().display()))152 {153 return false;154 }155 else156 {157 IHTMLElement parent = elem.parentElement();158 if (parent == null)159 {160 return true;161 }162 else163 {164 return isVisible(parent);165 }166 }167 }168 @Override169 public boolean isDisplayed()170 {171 return isVisible(watijElem);172 }173 @Override174 public boolean isEnabled()175 {176 return !watijElem.queryInterface(IHTMLElement3.class).disabled();177 }178 @Override179 public boolean isSelected()180 {181 if ("input".equalsIgnoreCase(watijElem.tagName()))182 {183 return watijElem.queryInterface(IHTMLInputElement.class).checked();184 }185 else if ("option".equalsIgnoreCase(watijElem.tagName()))186 {187 return watijElem.queryInterface(IHTMLOptionElement.class).selected();188 }189 throw new UnsupportedOperationException(190 "Unable to determine if element is selected. Tag name is: " + watijElem.tagName());191 }192 @Override193 public void sendKeys(CharSequence... seqs)194 {195 StringBuilder builder = new StringBuilder();196 for (CharSequence seq : seqs)197 {198 builder.append(seq);199 }200 if ("textarea".equalsIgnoreCase(watijElem.tagName()))201 {202 IHTMLTextAreaElement textarea = watijElem.queryInterface(IHTMLTextAreaElement.class);203 textarea.value(builder.toString());204 }205 else if ("file".equals(watijElem.queryInterface(IHTMLInputElement.class).type()))206 {207 String path = builder.toString();208 ScriptRunner.runFileOkScript(path);209 watijElem.click();210 }211 else212 {213 IHTMLInputElement input = watijElem.queryInterface(IHTMLInputElement.class);214 input.value(builder.toString());215 }216 }217 @Override218 public void submit()219 {220 watijElem.queryInterface(IHTMLFormElement.class).submit();221 }222 @Override223 public WebElement findElementByCssSelector(String css)224 {225 return finder.findElement(FindType.CSS, css, driver.getImplicitWait());226 }227 @Override228 public List<WebElement> findElementsByCssSelector(String css)229 {230 return finder.findElements(FindType.CSS, css, driver.getImplicitWait());231 }232 @Override233 public WebElement findElementByTagName(String tagName)234 {235 return finder.findElement(FindType.TAG_NAME, tagName, driver.getImplicitWait());236 }237 @Override238 public List<WebElement> findElementsByTagName(String tagName)239 {240 return finder.findElements(FindType.TAG_NAME, tagName, driver.getImplicitWait());241 }242 @Override243 public WebElement findElementByXPath(String xpath)244 {245 xpath = XPathUtils.convertXPath(xpath);246 return finder.findElement(FindType.XPATH, xpath, driver.getImplicitWait());247 }248 @Override249 public List<WebElement> findElementsByXPath(String xpath)250 {251 xpath = XPathUtils.convertXPath(xpath);252 return finder.findElements(FindType.XPATH, xpath, driver.getImplicitWait());253 }254 @Override255 public WebElement findElementByLinkText(String linkText)256 {257 return finder.findElement(FindType.LINK_TEXT, linkText, driver.getImplicitWait());258 }259 @Override260 public WebElement findElementByPartialLinkText(String partialLinkText)261 {262 return finder.findElement(FindType.PARTIAL_LINK_TEXT, partialLinkText, driver.getImplicitWait());263 }264 @Override265 public List<WebElement> findElementsByLinkText(String linkText)266 {267 return finder.findElements(FindType.XPATH, linkText, driver.getImplicitWait());268 }269 @Override270 public List<WebElement> findElementsByPartialLinkText(String partialLinkText)271 {272 return finder.findElements(FindType.PARTIAL_LINK_TEXT, partialLinkText, driver.getImplicitWait());273 }274 @Override275 public WebElement findElementById(String id)276 {277 return finder.findElement(FindType.ID, id, driver.getImplicitWait());278 }279 @Override280 public List<WebElement> findElementsById(String id)281 {282 return finder.findElements(FindType.XPATH, id, driver.getImplicitWait());283 }284 @Override285 public WebDriver getWrappedDriver()286 {287 return driver;288 }289}...

Full Screen

Full Screen

Source:WebInterfaceTesting.java Github

copy

Full Screen

...36 driver.findElement(By.cssSelector("h2")).click();37 assertThat(driver.findElement(By.cssSelector("h2")).getText(), is("Page Not Found"));38 driver.findElement(By.cssSelector("html")).click();39 {40 List<WebElement> elements = driver.findElements(By.linkText("Home Page."));41 assert (elements.size() > 0);42 }43 driver.findElement(By.linkText("Home Page.")).click();44 assertThat(driver.getTitle(), is("Java HTTP server"));45 try {46 driver.close();47 } catch (Exception e) {48 }49 }50 @Test51 public void TestElementsFromTestPage() {52 driver.get("http://localhost:8081/");53 driver.manage().window().setSize(new Dimension(1382, 744));54 driver.findElement(By.linkText("test page")).click();55 {56 List<WebElement> elements = driver.findElements(By.cssSelector("tr:nth-child(2) img"));57 assert (elements.size() > 0);58 }59 {60 List<WebElement> elements = driver.findElements(By.cssSelector("tr:nth-child(3) img"));61 assert (elements.size() > 0);62 }63 {64 List<WebElement> elements = driver.findElements(By.cssSelector("tr:nth-child(4) img"));65 assert (elements.size() > 0);66 }67 {68 List<WebElement> elements = driver.findElements(By.cssSelector("tr:nth-child(6) img"));69 assert (elements.size() > 0);70 }71 {72 List<WebElement> elements = driver.findElements(By.cssSelector("tr:nth-child(7) img"));73 assert (elements.size() > 0);74 }75 assertThat(driver.getTitle(), is("Welcome!"));76 {77 List<WebElement> elements = driver.findElements(By.cssSelector("tr:nth-child(1) img"));78 assert (elements.size() > 0);79 }80 try {81 driver.close();82 } catch (Exception e) {83 }84 }85 @Test86 public void textFileLink() {87 driver.get("http://localhost:8081/");88 driver.manage().window().setSize(new Dimension(1382, 744));89 driver.findElement(By.linkText("test page")).click();90 driver.findElement(By.linkText("do TXT files work")).click();91 assertThat(driver.findElement(By.cssSelector("pre")).getText(), is("Hello TXT works"));92 }93 @Test94 public void testUrlWithSpacePage() {95 driver.get("http://localhost:8081/");96 driver.manage().window().setSize(new Dimension(1382, 744));97 driver.findElement(By.linkText("test page")).click();98 {99 List<WebElement> elements = driver.findElements(By.linkText("do URLs with spaces work"));100 assert (elements.size() > 0);101 }102 driver.findElement(By.linkText("do URLs with spaces work")).click();103 driver.findElement(By.cssSelector("html")).click();104 {105 List<WebElement> elements = driver.findElements(By.linkText("back"));106 assert (elements.size() > 0);107 }108 try {109 driver.close();110 } catch (Exception e) {111 }112 }113 @Test114 public void testUrlWithProcent20Page() {115 driver.get("http://localhost:8081/");116 driver.manage().window().setSize(new Dimension(1382, 744));117 driver.findElement(By.linkText("test page")).click();118 assertThat(driver.findElement(By.linkText("do URLs with %20 work")).getText(), is("do URLs with %20 work"));119 driver.findElement(By.linkText("do URLs with %20 work")).click();120 {121 List<WebElement> elements = driver.findElements(By.linkText("back"));122 assert (elements.size() > 0);123 }124 driver.findElement(By.linkText("back")).click();125 try {126 driver.close();127 } catch (Exception e) {128 }129 }130 @Test131 public void testExternalLink() {132 driver.get("http://localhost:8081/");133 driver.manage().window().setSize(new Dimension(1382, 744));134 driver.findElement(By.linkText("test page")).click();135 assertThat(driver.findElement(By.linkText("do external links work?")).getText(), is("do external links work?"));136 driver.findElement(By.linkText("do external links work?")).click();137 try {138 driver.close();139 } catch (Exception e) {140 }141 }142 @Test143 public void testSimpleLinkPage() {144 driver.get("http://localhost:8081/");145 driver.manage().window().setSize(new Dimension(1382, 744));146 driver.findElement(By.linkText("test page")).click();147 assertThat(driver.findElement(By.linkText("do simple relative internal links work?")).getText(),148 is("do simple relative internal links work?"));149 driver.findElement(By.linkText("do simple relative internal links work?")).click();150 {151 List<WebElement> elements = driver.findElements(By.linkText("back"));152 assert (elements.size() > 0);153 }154 driver.findElement(By.linkText("back")).click();155 try {156 driver.close();157 } catch (Exception e) {158 }159 }160 @Test161 public void testAbsoluteLink() {162 driver.get("http://localhost:8081/");163 driver.manage().window().setSize(new Dimension(951, 603));164 driver.findElement(By.linkText("test page")).click();165 driver.findElement(By.cssSelector("center")).click();166 assertThat(driver.findElement(By.linkText("do general absolute links work")).getText(),167 is("do general absolute links work"));168 driver.findElement(By.linkText("do general absolute links work")).click();169 {170 List<WebElement> elements = driver.findElements(By.linkText("back"));171 assert (elements.size() > 0);172 }173 driver.findElement(By.linkText("back")).click();174 try {175 driver.close();176 } catch (Exception e) {177 }178 }179}...

Full Screen

Full Screen

Source:ResultPage.java Github

copy

Full Screen

...30// @FindBy(xpath = "//aside/div")31// private List<WebElement> filter;32 public void insertPrice(String str) {33// for(WebElement webElement : filter){34// workList = webElement.findElements(By.xpath(".//div[contains(text(), 'Цена')]"));35// if (!workList.isEmpty()) break;36// }37//38// scrollToElement(workList.get(0));39// workList.get(0).findElement(By.xpath("./..//p[contains(text(), 'до')]/../input")).click();40// workList.get(0).findElement(By.xpath("./..//p[contains(text(), 'до')]/../input")).sendKeys(Keys.CONTROL, "a");41// workList.get(0).findElement(By.xpath("./..//p[contains(text(), 'до')]/../input")).sendKeys(Keys.BACK_SPACE);42// workList.get(0).findElement(By.xpath("./..//p[contains(text(), 'до')]/../input")).sendKeys(str);43// waitElementChange(workList.get(0).findElement(By.xpath("./..//p[contains(text(), 'до')]/../input")), str);44// workList = null;45 scrollToElement(inputMaxPrice);46 inputMaxPrice.click();47 inputMaxPrice.sendKeys(Keys.CONTROL, "a");48 inputMaxPrice.sendKeys(Keys.BACK_SPACE);49 inputMaxPrice.sendKeys(str);50 waitElementChange(inputMaxPrice, str);51 }52 public void clickOnCheckBox(String str) {53 switch (str) {54 case "высокий рейтинг":55 scrollToElement(highRating);56 highRating.click();57 break;58 default:59 Assert.fail("Поле " + str + " не найдено");60 }61 }62 public void checkWirelessInterface(String str) {63// for (WebElement webElement : filter){64// workList = webElement.findElements(By.xpath(".//div[contains(text(), 'Беспроводные интерфейсы')]"));65// if (!workList.isEmpty()) break;66// }67//68// scrollToElement(workList.get(0));69// workList.get(0).findElement(By.xpath("./..//span[contains(text(), 'NFC')]/..")).click();70// workList = null;71 scrollToElement(wirelessInterface);72 if (!wirelessInterface.findElements(By.xpath(".//span[contains(text(), '" + str + "')]/..")).isEmpty()) {73 wirelessInterface.findElement(By.xpath(".//span[contains(text(), '" + str + "')]/..")).click();74 while (true) {75 if (newItems.isEmpty()) break;76 try {77 Thread.sleep(500);78 } catch (InterruptedException e) {79 e.printStackTrace();80 }81 }82 } else {83 throw new NotFoundException();84 }85 }86 public void addToCart(int count) {87 waitLoadPage();88 if (searchResult.size() >= (count * 2)) {89 for (int i = 0; i < count * 2; i++) {90 if (!(i % 2 == 0)) {91 if (!(searchResult.get(i).findElements(By.xpath(".//div[text()='Узнать о поступлении']")).size()==0)){92 count = count + 2;93 }94 else {95 scrollToElement(searchResult.get(i));96 searchResult.get(i).findElement(By.xpath(".//div[text()='В корзину']")).click();97 Products.getProductList().add(new Product(mainInfo.get(i).getText(), searchResult.get(i).98 findElement(By.xpath(".//span[contains(text(),'₽')]")).getText()));99 if (!searchResult.get(i).findElements(By.xpath(".//div[text()='В корзину']")).isEmpty()) {100 try {101 Thread.sleep(500);102 } catch (InterruptedException e) {103 e.printStackTrace();104 }105 }106 }107 }108 }109 }110 }111 public void clickCart() {112 scrollToElement(cart);113 cart.click();...

Full Screen

Full Screen

Source:PageHelper.java Github

copy

Full Screen

...23 public WebDriver getWebDriver() {24 return webDriverProvider.getWebDriver();25 }26 public WebElement findElement(final By bySelector) {27 return firstOrNull(findElements(bySelector));28 }29 public List<WebElement> findElements(By bySelector) {30 return findElements((by) -> getWebDriver().findElements(by), bySelector);31 }32 private List<WebElement> findElements(33 final Function<By, List<WebElement>> findElements, final By bySelector) {34 try {35 return pollWithTimeout()36 .until(37 (WebDriver driver) -> {38 List<WebElement> elements = findElements.apply(bySelector);39 return isEmpty(elements) ? null : elements;40 });41 } catch (TimeoutException exception) {42 throw new RuntimeException("Failed to find element matching '" + bySelector + "'", exception);43 }44 }45 public WebElement findChildElement(final WebElement parentElement, final By bySelector) {46 return firstOrNull(findChildElements(parentElement, bySelector));47 }48 public List<WebElement> findChildElements(final WebElement parentElement, final By bySelector) {49 return findElements(parentElement::findElements, bySelector);50 }51 public void waitUntilTrue(final Predicate predicate) {52 pollWithTimeout()53 .until(54 webDriver -> {55 try {56 return predicate.executeWithPredicate();57 } catch (final Exception exception) {58 return false;59 }60 });61 }62 public void executeWhenStable(final Task task) {63 final AtomicReference<Exception> lastException = new AtomicReference<>();64 try {65 pollWithTimeout()66 .until(67 webDriver -> {68 try {69 task.execute();70 return true;71 } catch (final Exception exception) {72 lastException.set(exception);73 return false;74 }75 });76 } catch (final TimeoutException exception) { // ignore TimeoutException77 throw new RuntimeException("Failed to execute task within timeout.", lastException.get());78 }79 }80 public void waitUntilVisible(WebElement webElement) {81 try {82 pollWithTimeout().until((WebDriver innerDriver) -> webElement.isDisplayed());83 } catch (TimeoutException exception) {84 throw new RuntimeException(85 "Timeout while waiting for element to become visible: '" + webElement + "'", exception);86 }87 }88 /** This takes care of element being removed/refreshed from DOM */89 public <T> T waitForElementUntil(ExpectedCondition<T> condition) {90 return pollWithTimeout().until(ExpectedConditions.refreshed(condition));91 }92 private FluentWait<WebDriver> pollWithTimeout() {93 return new WebDriverWait(getWebDriver(), TIME_OUT)94 .ignoring(StaleElementReferenceException.class)95 .pollingEvery(Duration.ofMillis(500));96 }97 public boolean assertElementPresent(By selector) {98 // this will throw an exception if the element is not present99 return findElement(selector) != null;100 }101 public boolean isElementPresent(By selector) {102 return findOptionalElement(selector) != null;103 }104 public WebElement findOptionalElement(By by) {105 return firstOrNull(getWebDriver().findElements(by));106 }107 public WebElement findOptionalChildElement(WebElement menu, By by) {108 return firstOrNull(menu.findElements(by));109 }110 private WebElement firstOrNull(List<WebElement> elements) {111 if (elements.size() < 1) {112 return null;113 }114 return elements.get(0);115 }116 public void click(By by) {117 executeWhenStable(() -> findElement(by).click());118 }119 public List<WebElement> findOptionalElements(By by) {120 return getWebDriver().findElements(by);121 }122 @FunctionalInterface123 public interface Task {124 void execute();125 }126 @FunctionalInterface127 public interface Predicate {128 boolean executeWithPredicate();129 }130}...

Full Screen

Full Screen

Source:WebDriverEventListener.java Github

copy

Full Screen

...45 */46 void afterNavigateForward(WebDriver driver);47 /**48 * Called before {@link WebDriver#findElement WebDriver.findElement(...)}, or49 * {@link WebDriver#findElements WebDriver.findElements(...)}, or {@link WebElement#findElement50 * WebElement.findElement(...)}, or {@link WebElement#findElement WebElement.findElements(...)}.51 *52 * @param element will be <code>null</code>, if a find method of <code>WebDriver</code> is called.53 */54 void beforeFindBy(By by, WebElement element, WebDriver driver);55 /**56 * Called after {@link WebDriver#findElement WebDriver.findElement(...)}, or57 * {@link WebDriver#findElements WebDriver.findElements(...)}, or {@link WebElement#findElement58 * WebElement.findElement(...)}, or {@link WebElement#findElement WebElement.findElements(...)}.59 *60 * @param element will be <code>null</code>, if a find method of <code>WebDriver</code> is called.61 */62 void afterFindBy(By by, WebElement element, WebDriver driver);63 /**64 * Called before {@link WebElement#click WebElement.click()}.65 */66 void beforeClickOn(WebElement element, WebDriver driver);67 /**68 * Called after {@link WebElement#click WebElement.click()}. Not called, if an exception is69 * thrown.70 */71 void afterClickOn(WebElement element, WebDriver driver);72 /**...

Full Screen

Full Screen

Source:SearchingEventListener.java Github

copy

Full Screen

...21public interface SearchingEventListener extends Listener {22 /**23 * Called before {@link org.openqa.selenium.WebDriver#findElement WebDriver.findElement(...)},24 * or25 * {@link org.openqa.selenium.WebDriver#findElements WebDriver.findElements(...)}, or26 * {@link org.openqa.selenium.WebElement#findElement WebElement.findElement(...)}, or27 * {@link org.openqa.selenium.WebElement#findElement WebElement.findElements(...)}.28 *29 * @param element will be <code>null</code>, if a find method of <code>WebDriver</code>30 * is called.31 * @param by locator being used32 * @param driver WebDriver33 */34 void beforeFindBy(By by, WebElement element, WebDriver driver);35 /**36 * Called after {@link org.openqa.selenium.WebDriver#findElement WebDriver.findElement(...)},37 * or38 * {@link org.openqa.selenium.WebDriver#findElements WebDriver.findElements(...)}, or39 * {@link org.openqa.selenium.WebElement#findElement WebElement.findElement(...)}, or40 * {@link org.openqa.selenium.WebElement#findElement WebElement.findElements(...)}.41 *42 * @param element will be <code>null</code>, if a find method of <code>WebDriver</code>43 * is called.44 * @param by locator being used45 * @param driver WebDriver46 */47 void afterFindBy(By by, WebElement element, WebDriver driver);48}

Full Screen

Full Screen

Source:Assignment2ImplementList.java Github

copy

Full Screen

...28 driver.findElement(By.xpath("//label[@for='Men - Fashion Bags']")).click();29 Thread.sleep(2000);30 System.out.println(driver.findElement(By.xpath("//*[@class='filter-container']/div/div[@class='length']")).getText());31 32 List<WebElement> brand = driver.findElements(By.xpath("//div[@class='brand']"));33 //Interface<Generic> variable name = finding the element part.34 List<WebElement> name = driver.findElements(By.xpath("//div[@class='name']"));35 36 for (int i = 0; i < brand.size(); i++) {37 WebElement brandcount = brand.get(i);38 String text = brandcount.getText();39 System.out.println("Brands are: " +text);40 }41 42 for (int i = 0; i < name.size(); i++) {4344 WebElement webElement = name.get(i);45 String text2 = webElement.getText();46 System.out.println("Names are:" + text2);47 48 } ...

Full Screen

Full Screen

Source:WebPageTables.java Github

copy

Full Screen

...10public class WebPageTables11{12 private static void dynamicTable(WebDriver driver,int colNum)13 {14 List<WebElement> t1tdata = driver.findElements(By.xpath("//table[@id='t1']//tr[*]//td["+colNum+"]"));15 System.out.println("Total No.of Rows in column no."+colNum+" is : "+t1tdata.size());16 }17 public static void main(String[] args)18 {19 System.setProperty("webdriver.chrome.driver","./drivers/chromedriver.exe");20 WebDriver driver = new ChromeDriver();21/* driver.get("file:///D:/KCSM6/HTML/StaticTable.html");22//Static Table23 //findElements() of WebDriver interface24 List<WebElement> trows = driver.findElements(By.xpath("//tr")); //here driver var acts as WebDriver(i) as well as findElements()25 System.out.println("Total No.of Rows in Webpage : "+trows.size());26 27 //findElements() of WebElement interface 28 WebElement table2 = driver.findElement(By.id("t2"));29 List<WebElement> t2rows = table2.findElements(By.tagName("tr")); //here table2 var acts as WebElement(i) as well as findElements()30 System.out.println("Total No.of Rows in table 2 : "+t2rows.size());*/31 32//Dynamic Table33 driver.get("file:///D:/KCSM6/HTML/DynamicTable.html");34 dynamicTable(driver, 5);35 } ...

Full Screen

Full Screen

findElements

Using AI Code Generation

copy

Full Screen

1public class FindElementByLinkText{2 public static void main(String[] args) throws InterruptedException{3 WebDriver driver;4 System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");5 driver = new ChromeDriver();6 String expectedTitle = "Welcome: Mercury Tours";7 String actualTitle = "";8 driver.get(baseUrl);9 actualTitle = driver.getTitle();10 if (actualTitle.contentEquals(expectedTitle)){11 System.out.println("Test Passed!");12 } else {13 System.out.println("Test Failed");14 }15 driver.close();16 System.exit(0);17 }18}

Full Screen

Full Screen

findElements

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5import java.util.List;6public class FindElements {7 public static void main(String[] args) {8 System.setProperty("webdriver.chrome.driver", "C:\\Users\\navee\\Downloads\\chromedriver_win32\\chromedriver.exe");9 WebDriver driver = new ChromeDriver();10 List<WebElement> list = driver.findElements(By.className("form-control"));11 System.out.println(list.size());12 for(WebElement element: list){13 System.out.println(element.getText());14 }15 driver.close();16 }17}18WebElement element = driver.findElement(By.linkText("Selenium Easy"));19The findElement() method can be used to find an element by a partial link text. The partial link text is the text that is displayed on the link. For example, the link

Full Screen

Full Screen

findElements

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5import java.util.List;6public class FindElements {7 public static void main(String[] args) {8 System.setProperty("webdriver.chrome.driver","C:\\Users\\My\\Downloads\\chromedriver_win32\\chromedriver.exe");9 WebDriver driver = new ChromeDriver();10 driver.get(baseUrl);11 List<WebElement> links = driver.findElements(By.tagName("a"));12 System.out.println("Size of all links on this page is: " + links.size());13 for (int i=0; i<links.size(); i++){14 System.out.println("Link text is: " + links.get(i).getText());15 }16 driver.close();17 }18}19import java.util.Random;20public class RandomNumber {21 public static void main(String[] args) {22 Random random = new Random();23 int randomNumber = random.nextInt(10) + 1;24 if (randomNumber == 1 || randomNumber == 3 ||

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful