How to use or method of org.openqa.selenium.support.ui.ExpectedConditions class

Best Selenium code snippet using org.openqa.selenium.support.ui.ExpectedConditions.or

Source:Select.java Github

copy

Full Screen

1package com.autumn.ui.actionFactory.element;2/*-3 * #%L4 * autumn-ui5 * %%6 * Copyright (C) 2021 Deutsche Telekom AG7 * %%8 * Licensed under the Apache License, Version 2.0 (the "License");9 * you may not use this file except in compliance with the License.10 * You may obtain a copy of the License at11 * 12 * http://www.apache.org/licenses/LICENSE-2.013 * 14 * Unless required by applicable law or agreed to in writing, software15 * distributed under the License is distributed on an "AS IS" BASIS,16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.17 * See the License for the specific language governing permissions and18 * limitations under the License.19 * #L%20 */21import com.autumn.ui.actionFactory.MoreExpectedConditions;22import com.autumn.ui.driver.DriverManager;23import com.autumn.reporting.extentReport.Logger;24import org.openqa.selenium.By;25import org.openqa.selenium.TimeoutException;26import org.openqa.selenium.WebElement;27import org.openqa.selenium.support.ui.ExpectedConditions;28import java.util.List;29public class Select extends UIElement {30 public Select(By by, String pageName, String elementName) {31 super(by, pageName, elementName);32 }33 34 public boolean isMultiple() {35 return new org.openqa.selenium.support.ui.Select(getWrappedElement()).isMultiple();36 }37 38 public void deselectByIndex(int index) {39 Logger.logInfo(40 "De-select [" + getElementName() + "] option at position [" + index + "] on [" + getPageName() + "]");41 new org.openqa.selenium.support.ui.Select(getWrappedElement()).deselectByIndex(index);42 }43 44 public void selectByValue(String value) {45 Logger.logInfo(46 "Select [" + getElementName() + "] option with value [" + value + "] on [" + getPageName() + "]");47 new org.openqa.selenium.support.ui.Select(getWrappedElement()).selectByValue(value);48 }49 50 public WebElement getFirstSelectedOption() {51 return new org.openqa.selenium.support.ui.Select(getWrappedElement()).getFirstSelectedOption();52 }53 54 public void selectByVisibleText(String text) {55 Logger.logInfo("Select [" + getElementName() + "] option with text [" + text + "] on [" + getPageName() + "]");56 new org.openqa.selenium.support.ui.Select(getWrappedElement()).selectByVisibleText(text);57 }58 59 public void deselectByValue(String value) {60 Logger.logInfo(61 "De-Select [" + getElementName() + "] option with value [" + value + "] on [" + getPageName() + "]");62 new org.openqa.selenium.support.ui.Select(getWrappedElement()).deselectByValue(value);63 }64 65 public void deselectAll() {66 Logger.logInfo("De-select [" + getElementName() + "] all options on [" + getPageName() + "]");67 new org.openqa.selenium.support.ui.Select(getWrappedElement()).deselectAll();68 }69 70 public List<WebElement> getAllSelectedOptions() {71 return new org.openqa.selenium.support.ui.Select(getWrappedElement()).getAllSelectedOptions();72 }73 74 public List<WebElement> getOptions() {75 return new org.openqa.selenium.support.ui.Select(getWrappedElement()).getOptions();76 }77 78 public void deselectByVisibleText(String text) {79 Logger.logInfo(80 "De-select [" + getElementName() + "] option with text [" + text + "] on [" + getPageName() + "]");81 new org.openqa.selenium.support.ui.Select(getWrappedElement()).deselectByVisibleText(text);82 }83 84 public void selectByIndex(int index) {85 Logger.logInfo(86 "Select [" + getElementName() + "] option at position [" + index + "] on [" + getPageName() + "]");87 new org.openqa.selenium.support.ui.Select(getWrappedElement()).selectByIndex(index);88 }89 90 public void waitUntilSelected() {91 Logger.logInfo("Wait until [" + getElementName() + "] option is selected on [" + getPageName() + "]");92 try {93 DriverManager.getWebDriverElementWait().until(ExpectedConditions.elementSelectionStateToBe(getBy(), true));94 } catch (TimeoutException e) {95 // swallowing the exception as this function is meant to be used as pre-step to96 // a main-step, so no need to fail it if we get TimeOutException97 }98 }99 100 public void waitUntilDeSelected() {101 Logger.logInfo("Wait until [" + getElementName() + "] option is de-selected on [" + getPageName() + "]");102 try {103 DriverManager.getWebDriverElementWait().until(ExpectedConditions.elementSelectionStateToBe(getBy(), false));104 } catch (TimeoutException e) {105 // swallowing the exception as this function is meant to be used as pre-step to106 // a main-step, so no need to fail it if we get TimeOutException107 }108 }109 110 public void waitUntilOptionToBeSelectedByVisibeText(String optionText) {111 Logger.logInfo("Wait until [" + getElementName() + "] option with text [" + optionText112 + "] is selected on [" + getPageName() + "]");113 try {114 DriverManager.getWebDriverElementWait().until(MoreExpectedConditions.optionToBeSelectedInElement(115 new org.openqa.selenium.support.ui.Select(getWrappedElement()), optionText, true));116 } catch (TimeoutException e) {117 // swallowing the exception as this function is meant to be used as pre-step to118 // a main-step, so no need to fail it if we get TimeOutException119 }120 }121 122 public void waitUntilOptionToBeSelectedByValue(String optionValue) {123 Logger.logInfo("Wait until [" + getElementName() + "] option with value [" + optionValue124 + "] is selected on [" + getPageName() + "]");125 try {126 DriverManager.getWebDriverElementWait().until(MoreExpectedConditions.optionToBeSelectedInElement(127 new org.openqa.selenium.support.ui.Select(getWrappedElement()), optionValue, false));128 } catch (TimeoutException e) {129 // swallowing the exception as this function is meant to be used as pre-step to130 // a main-step, so no need to fail it if we get TimeOutException131 }132 }133}...

Full Screen

Full Screen

Source:SearchResultsPage.java Github

copy

Full Screen

1package locus.assignment.web.page.classes;23import java.time.Duration;4import java.util.Iterator;5import java.util.List;6import java.util.Set;7import java.util.concurrent.TimeUnit;89import org.openqa.selenium.By;10import org.openqa.selenium.JavascriptExecutor;11import org.openqa.selenium.NoSuchElementException;12import org.openqa.selenium.WebDriver;13import org.openqa.selenium.WebElement;14import org.openqa.selenium.chrome.ChromeDriver;15import org.openqa.selenium.interactions.Actions;16import org.openqa.selenium.support.FindAll;17import org.openqa.selenium.support.FindBy;18import org.openqa.selenium.support.How;19import org.openqa.selenium.support.PageFactory;20import org.openqa.selenium.support.ui.ExpectedCondition;21import org.openqa.selenium.support.ui.ExpectedConditions;22import org.openqa.selenium.support.ui.FluentWait;23import org.openqa.selenium.support.ui.Select;24import org.openqa.selenium.support.ui.Wait;25import org.openqa.selenium.support.ui.WebDriverWait;26import org.testng.AssertJUnit;27import org.testng.Reporter;28import org.testng.asserts.Assertion;2930import locus.assignment.property.readers.or.utils.CommonFunctions;3132import org.testng.Assert;3334public class SearchResultsPage {35 //SearchPage36 37 38 private WebDriver chromeDriver;39 private Wait<WebDriver> wait;40 private String brand_name;41 @FindBy(how =How.CSS,using ="._3vKPvR" )42 private WebElement searchBrandTextBox;43 44 @FindBy(how =How.CSS,using ="._1YoBfV :first-child")45 private WebElement filterBox;46 47 @FindBy(how=How.CSS,using="SPAN[class='_2yAnYN']")48 private WebElement searchResultMessage;49 50 @FindBy(how=How.CSS,using="[class='_2wQvxh _1WV8jE']:nth-child(1)")51 private WebElement searchBrandCheckBox;52 53 54 @FindBy(how=How.CSS,using="div._3O0U0u")55 private List<WebElement> all_rows ;56 57 @FindBy(how=How.CSS,using="div._3O0U0u > div")58 private List<WebElement> all_search_results ;59 60 61 @FindBy(how=How.CSS,using="[data-tkid*='.SEARCH'] ._2B_pmu:nth-child(1)")62 private WebElement search_brand_text ;63 64 65 66 @FindBy(how=How.CSS,using="div._3O0U0u > div *> img[src*='jpeg']")67 private List<WebElement> all_images ;68 69 70 //@FindBy(how=How.XPATH,using="//div[@class='_3O0U0u'][1]/*")71 @FindBy(how=How.CSS,using="img[src*='https://rukminim1.flixcart.com/'][alt]:nth-child(1)")72 private List<WebElement> all_results ;73 74 75 76 public SearchResultsPage(WebDriver driver)77 {78 chromeDriver=driver;79 PageFactory.initElements(chromeDriver, this);80 wait = new FluentWait(chromeDriver)81 .withTimeout(Duration.ofSeconds(30))82 .pollingEvery(Duration.ofSeconds(5))83 .ignoring(NoSuchElementException.class);84 Reporter.log("SearchResultsPage initialised"); 85 CommonFunctions.loadAllImages(chromeDriver ); 86 87 88 }89 90 public SearchResultsPage applyFilter(String value)91 {92 wait.until(ExpectedConditions.visibilityOf(filterBox));93 Select select=new Select(filterBox);94 select.selectByValue(value);95 chromeDriver.navigate().refresh();96 Reporter.log("MaxFilter Applied"); 97 return this;98 }99 public SearchResultsPage applyBrandCheck(String brand)100 {101 brand_name=brand;102 wait.until(CommonFunctions.waitUntillPageIsFullyLoaded());103 searchBrandTextBox.sendKeys(brand); 104 wait.until(ExpectedConditions.elementToBeClickable(searchBrandCheckBox));105 106 Reporter.log("Brand is selected"); 107 searchBrandCheckBox.click();108 109 110 return this;111 }112 113 114 public SearchResultsPage checkAllFirstRowItems()115 {116 search_brand_text.getText().equals(brand_name);117 Reporter.log("First result is of "+brand_name);118 119 120 try {121 Thread.sleep(3000);122 } catch (InterruptedException e) {123 // TODO Auto-generated catch block124 e.printStackTrace();125 }126 127 for(int i=0;i<all_results.size()/all_rows.size();i++)128 {129 wait.until(ExpectedConditions.visibilityOf(all_images.get(i)));130 131 CommonFunctions.checkImage(all_images.get(i), chromeDriver);132; boolean condition=all_images.get(i).isDisplayed(); 133 Reporter.log((i+1)+"th image ="+all_images.get(i).getAttribute("src")+" is displayed.");134 Assert.assertEquals(condition, true);135 }136 137 return this;138 }139 140 public ProductDetailsPage gotoFirstProduct()141 {142 PageFactory.initElements(chromeDriver, this);143 144 wait.until(ExpectedConditions.visibilityOf(all_results.get(0)));145 146 wait.until(CommonFunctions.waitUntillPageIsFullyLoaded());147 Actions actions = new Actions(chromeDriver);148 actions.moveToElement(all_results.get(0)).perform();;149 wait.until(ExpectedConditions.elementToBeClickable(all_results.get(0)));150 all_results.get(0).click();151 CommonFunctions.switchTab(chromeDriver);152 wait.until(CommonFunctions.waitUntillPageIsFullyLoaded());153 Reporter.log("First Product from search results is clicked"); 154 return new ProductDetailsPage(chromeDriver);155 }156 157 158 public SearchResultsPage checkItemHasBeenSearched()159 {160 wait.until(ExpectedConditions.elementToBeClickable(searchResultMessage));161 String search_result_message=searchResultMessage.getText(); 162 AssertJUnit.assertEquals(true, search_result_message.endsWith("\"shoes\""));163 AssertJUnit.assertEquals(true, search_result_message.contains("40"));164 Reporter.log("Item Searched Properly and with correct Number of Results"); 165 return this;166 }167 168} ...

Full Screen

Full Screen

Source:URLUtils.java Github

copy

Full Screen

1package org.keycloak.testsuite.util;2import org.jboss.logging.Logger;3import org.openqa.selenium.TimeoutException;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.ie.InternetExplorerDriver;6import org.openqa.selenium.support.ui.ExpectedCondition;7import org.openqa.selenium.support.ui.WebDriverWait;8import java.util.regex.Pattern;9import static org.openqa.selenium.support.ui.ExpectedConditions.not;10import static org.openqa.selenium.support.ui.ExpectedConditions.or;11import static org.openqa.selenium.support.ui.ExpectedConditions.urlMatches;12import static org.openqa.selenium.support.ui.ExpectedConditions.urlToBe;13/**14 * @author Vaclav Muzikar <vmuzikar@redhat.com>15 */16public final class URLUtils {17 public static void navigateToUri(WebDriver driver, String uri, boolean waitForMatch) {18 navigateToUri(driver, uri, waitForMatch, true);19 }20 private static void navigateToUri(WebDriver driver, String uri, boolean waitForMatch, boolean enableIEWorkaround) {21 Logger log = Logger.getLogger(URLUtils.class);22 log.info("starting navigation");23 // In IE, sometime the current URL is not correct; one of the indicators is that the target URL24 // equals the current URL25 if (driver instanceof InternetExplorerDriver && driver.getCurrentUrl().equals(uri)) {26 log.info("IE workaround: target URL equals current URL - refreshing the page");27 driver.navigate().refresh();28 }29 WaitUtils.waitForPageToLoad(driver);30 log.info("current URL: " + driver.getCurrentUrl());31 log.info("navigating to " + uri);32 driver.navigate().to(uri);33 if (waitForMatch) {34 // Possible login URL; this is to eliminate unnecessary wait when navigating to a secured page and being35 // redirected to the login page36 String loginUrl = "^[^\\?]+/auth/realms/[^/]+/(protocol|login-actions).+$";37 try {38 (new WebDriverWait(driver, 3)).until(or(urlMatches("^" + Pattern.quote(uri) + ".*$"), urlMatches(loginUrl)));39 } catch (TimeoutException e) {40 log.info("new current URL doesn't start with desired URL");41 }42 }43 WaitUtils.waitForPageToLoad(driver);44 log.info("new current URL: " + driver.getCurrentUrl());45 // In IE, after deleting the cookies for test realm, the first loaded page in master's admin console46 // contains invalid URL (misses #/realms/[realm] or contains state and code fragments), although the47 // address bar states the correct URL; seemingly this is another bug in IE WebDriver)48 if (enableIEWorkaround && driver instanceof InternetExplorerDriver49 && (driver.getCurrentUrl().matches("^[^#]+/#state=[^#/&]+&code=[^#/&]+$")50 || driver.getCurrentUrl().matches("^.+/auth/admin/[^/]+/console/$"))) {51 log.info("IE workaround: reloading the page after deleting the cookies...");52 navigateToUri(driver, uri, waitForMatch, false);53 }54 else {55 log.info("navigation complete");56 }57 }58 public static boolean currentUrlEqual(WebDriver driver, String url) {59 return urlCheck(driver, urlToBe(url));60 }61 public static boolean currentUrlDoesntEqual(WebDriver driver, String url) {62 return urlCheck(driver, not(urlToBe(url)));63 }64 public static boolean currentUrlStartWith(WebDriver driver, String url) {65 return urlCheck(driver, urlMatches("^" + Pattern.quote(url) + ".*$"));66 }67 public static boolean currentUrlDoesntStartWith(WebDriver driver, String url) {68 return urlCheck(driver, urlMatches("^(?!" + Pattern.quote(url) + ").+$"));69 }70 private static boolean urlCheck(WebDriver driver, ExpectedCondition condition) {71 return urlCheck(driver, condition, false);72 }73 private static boolean urlCheck(WebDriver driver, ExpectedCondition condition, boolean secondTry) {74 Logger log = Logger.getLogger(URLUtils.class);75 try {76 (new WebDriverWait(driver, 1, 100)).until(condition);77 }78 catch (TimeoutException e) {79 if (driver instanceof InternetExplorerDriver && !secondTry) {80 // IE WebDriver has sometimes invalid current URL81 log.info("IE workaround: checking URL failed at first attempt - refreshing the page and trying one more time...");82 driver.navigate().refresh();83 urlCheck(driver, condition, true);84 }85 else {86 return false;87 }88 }89 return true;90 }91}...

Full Screen

Full Screen

Source:D9_C1.java Github

copy

Full Screen

1package Day9;2import Utilities.WebDriverUtils;3import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.FluentWait;8import org.openqa.selenium.support.ui.Wait;9import org.openqa.selenium.support.ui.WebDriverWait;10import org.testng.annotations.BeforeMethod;11import org.testng.annotations.Ignore;12import org.testng.annotations.Test;13import java.time.Duration;14import java.util.NoSuchElementException;15import java.util.concurrent.TimeUnit;16public class D9_C1 {17 WebDriver driver;18 WebDriverWait wait;19 @BeforeMethod20 public void setup(){21 driver= WebDriverUtils.getDriver("chrome");22 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);23 new WebDriverWait(driver,100);24 }25 @Test26 public void implicitWait(){27 /*28 The Implicit Wait in Selenium is used to tell the web driver to29 wait for a certain amount of time before it throws a "No Such Element Exception".30 The default setting is 0. Once we set the time, the web driver will31 wait for the element for that time before throwing an exceptio32 */33 driver.get("https://google.com");34 driver.findElement(By.name("q"));35 }36 @Test37 public void explicitWait() throws InterruptedException {38 /*39 Explicit Wait40 The Explicit Wait in Selenium is used to tell the Web Driver to wait for41 certain conditions (Expected Conditions) or maximum time exceeded before42 throwing "ElementNotVisibleException" exception.43 It is an intelligent kind of wait, but it can be applied only for specified elements.44 It gives better options than implicit wait as it waits for dynamically loaded Ajax elements.45 */46 driver.get("https://google.com");47 wait.until(ExpectedConditions.titleIs("Google"));48 //Thread.sleep(5000);// it will wait for 549 wait.until(ExpectedConditions.elementToBeClickable(By.name("q")));50 }51 @Test52 public void explicitWaitPractice(){53 driver.get("https://www.amazon.com/");54 wait.until(ExpectedConditions.titleContains("Amazon"));55 String bestSeller= "Best Seller";56 wait.until(ExpectedConditions.textToBePresentInElement(driver.57 findElement(By.xpath("//a[@data-csa-c-slot-id='nav_cs_0']")),"Best Seller"));58 }59 public void clickableElement(By locator){60 wait.until(ExpectedConditions.elementToBeClickable(locator)).click();61 }62 public void visibleElement(By locator){63 wait.until(ExpectedConditions.presenceOfElementLocated(locator));64 }65 @Test66 public void praticeClickableElement(){67 driver.get("https://www.amazon.com/");68 visibleElement(By.cssSelector("#twotabsearchtextbox"));69 WebElement searchField= driver.findElement(By.cssSelector("#twotabsearchtextbox"));70 searchField.sendKeys("apple and oranges");71 clickableElement(By.cssSelector("#nav-search-submit-button"));72 }73 /*74 Fluent Wait75 The Fluent Wait in Selenium is used to define maximum76 time for the web driver to wait for a condition,77 as well as the frequency with which we want to78 check the condition before throwing an79 "ElementNotVisibleException" exception.80 It checks for the web element at regular81 intervals until the object is found or timeout happens.82 */83 @Test84 public void fluentWait(){85 driver.get("http://google.com");86 Wait<WebDriver>fluentWait=new FluentWait<WebDriver>(driver)87 .withTimeout(Duration.ofSeconds(30))88 .pollingEvery(Duration.ofSeconds(2))89 .ignoring(NoSuchElementException.class);90 fluentWait.until(driver->driver.findElement(By.name("q")));91 }92}...

Full Screen

Full Screen

Source:ChangeBrand.java Github

copy

Full Screen

1package com.innovation.pages.common.pages;23import java.util.concurrent.TimeUnit;45import org.openqa.selenium.WebDriver;6import org.openqa.selenium.support.PageFactory;7import org.openqa.selenium.support.ui.ExpectedConditions;8import org.openqa.selenium.support.ui.FluentWait;9import org.openqa.selenium.support.ui.Select;10import org.openqa.selenium.support.ui.Wait;11import org.openqa.selenium.support.ui.WebDriverWait;1213import com.innovation.misc.GlobalWaitTime;14import com.innovation.misc.LoggingControl;15import com.innovation.misc.SeleniumWaiter;16import com.innovation.pages.common.objects.OR_ChangeBrand;1718/**19 * @author M.Tahir, this class will select the required scheme for which the sanity has to be executed20 *21 */22public class ChangeBrand23{2425 WebDriver driver;26 LoggingControl loggingcontrol = new LoggingControl ();27 OR_ChangeBrand orChangeBrand = null;2829 public ChangeBrand (WebDriver driver)30 {31 this.driver = driver;32 orChangeBrand = PageFactory.initElements (driver, OR_ChangeBrand.class);33 }3435 public void clickChangeBrand ()36 {3738 // @formatter:off39 loggingcontrol.ConsoleLogger (new Object ()40 {41 }.getClass ().getEnclosingMethod ().getName (), driver);42 // @formatter:on4344 WebDriverWait wait = new WebDriverWait (driver, GlobalWaitTime.getIntWaitTime ());45 wait.until (ExpectedConditions.textToBePresentInElement (orChangeBrand.lnkChangeBrand, "Change brand"));46 wait.until (ExpectedConditions.elementToBeClickable ((orChangeBrand.lnkChangeBrand)));47 orChangeBrand.lnkChangeBrand.click ();48 }4950 public void selectBrand (String strBrand)51 {5253 // @formatter:off54 loggingcontrol.ConsoleLogger (new Object ()55 {56 }.getClass ().getEnclosingMethod ().getName (), driver);57 // @formatter:on5859 WebDriverWait wait = new WebDriverWait (driver, GlobalWaitTime.getIntWaitTime ());60 wait.until (ExpectedConditions.textToBePresentInElement (orChangeBrand.ddlChangeBrand, strBrand));6162 wait.until (ExpectedConditions.elementToBeClickable ((orChangeBrand.ddlChangeBrand)));63 orChangeBrand.ddlChangeBrand.click ();6465 Select oSelectBrand = new Select (orChangeBrand.ddlChangeBrand);66 oSelectBrand.selectByVisibleText (strBrand);6768 wait.until (ExpectedConditions.elementToBeClickable ((orChangeBrand.ddlChangeBrand)));69 orChangeBrand.ddlChangeBrand.click ();7071 String strBrandValue = oSelectBrand.getFirstSelectedOption ().getAttribute ("text");72 System.out.println ("Brand Selected is: " + strBrandValue);73 }7475 public void saveBrand ()76 {7778 // @formatter:off79 loggingcontrol.ConsoleLogger (new Object ()80 {81 }.getClass ().getEnclosingMethod ().getName (), driver);82 // @formatter:on8384 WebDriverWait wait = new WebDriverWait (driver, GlobalWaitTime.getIntWaitTime ());85 wait.until (SeleniumWaiter.jQueryAJAXCallsHaveCompleted ());8687 // Fluent wait added as generic wait starts failing after each couple of days. Will replace with generic wait when a88 // suitable solution found.89 Long intMaxTimeOut = (long) GlobalWaitTime.getIntWaitTime ();90 Wait<WebDriver> fWait = new FluentWait<WebDriver> (driver).withTimeout (intMaxTimeOut, TimeUnit.SECONDS).pollingEvery (1, TimeUnit.SECONDS);9192 fWait.until (ExpectedConditions.elementToBeClickable ((orChangeBrand.btnChangeBrand)));93 orChangeBrand.btnChangeBrand.click ();9495 }96} ...

Full Screen

Full Screen

Source:ICLoginPage.java Github

copy

Full Screen

1package com.dnastack.ddap.common.page;2import com.dnastack.ddap.common.TestingPersona;3import lombok.extern.slf4j.Slf4j;4import org.openqa.selenium.By;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.WebDriverWait;8import java.net.URI;9import java.util.function.Function;10import java.util.regex.Matcher;11import java.util.regex.Pattern;12import static com.dnastack.ddap.common.TestingPersona.*;13import static java.lang.String.format;14import static org.openqa.selenium.support.ui.ExpectedConditions.or;15import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;16@Slf4j17public class ICLoginPage {18 private WebDriver driver;19 public ICLoginPage(WebDriver driver) {20 this.driver = driver;21 log.info("Testing if {} is an IC login page", driver.getCurrentUrl());22 new WebDriverWait(driver, 5)23 .until(or(visibilityOfElementLocated(By.xpath("//a[contains(@href, '/login/persona')]")),24 // If persona login is disabled, check that there is a wallet login25 visibilityOfElementLocated(By.xpath("//a[contains(@href, '/login/wallet')]"))));26 }27 private By personaLoginButton(TestingPersona persona) {28 return By.xpath(format("//a[contains(@href, '%s')]", persona.getId()));29 }30 public <T extends AnyDdapPage> T loginAsPersona(TestingPersona persona, Function<WebDriver, T> pageConstructor) {31 driver.findElement(By.xpath("//a[contains(@href, '/login/persona')]")).click();32 new WebDriverWait(driver, 5)33 .until(visibilityOfElementLocated(personaLoginButton(persona)));34 driver.findElement(personaLoginButton(persona)).click();35 new WebDriverWait(driver, 5)36 .until(visibilityOfElementLocated(By.id("agree")));37 driver.findElement(By.id("agree")).click();38 return pageConstructor.apply(driver);39 }40 public String getRealm() {41 // FIXME when the realm name appears in the UI, we can get it from the UI element42 // (at the time of this writing, the current realm name isn't mentioned in visible UI)43 URI currentUrl = URI.create(driver.getCurrentUrl());44 Pattern realmExtractor = Pattern.compile("/identity/v1alpha/([A-Za-z0-9_-]{3,40})/authorize");45 Matcher matcher = realmExtractor.matcher(currentUrl.getPath());46 if (matcher.matches()) {47 return matcher.group(1);48 } else {49 throw new AssertionError("IC Login page path '" + currentUrl.getPath() + "' does not conform to expected format");50 }51 }52}

Full Screen

Full Screen

Source:WaitHelper.java Github

copy

Full Screen

1package pms.assignment.util;2import java.util.concurrent.TimeUnit;3import java.util.logging.Logger;4import org.openqa.selenium.JavascriptExecutor;5import org.openqa.selenium.NoSuchElementException;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.support.ui.ExpectedConditions;9import org.openqa.selenium.support.ui.FluentWait;10import org.openqa.selenium.support.ui.WebDriverWait;11import com.google.common.base.Predicate;12public class WaitHelper {13 14 private static Logger log=Logger.getLogger(WaitHelper.class.getName());15 WebDriverWait wait;16 FluentWait<WebDriver> fluentWait;17 JavascriptExecutor js;18 19 20 public WaitHelper(WebDriver driver) {21 this.wait = new WebDriverWait(driver, Constants.EXPLICIT_WAIT); 22 js= (JavascriptExecutor) driver;23 fluentWait = new FluentWait<WebDriver>(driver);24 fluentWait.pollingEvery(250, TimeUnit.MILLISECONDS);25 fluentWait.withTimeout(2, TimeUnit.MINUTES);26 fluentWait.ignoring(NoSuchElementException.class);27 }28 29 public void WaitForElementVisible(WebElement element) {30 log.info("Waiting for the element to be visible : " + element.toString());31 wait.until(ExpectedConditions.visibilityOf(element));32 }33 34 public void WaitForElementEnabled(WebElement element) {35 wait.until(ExpectedConditions.elementToBeClickable(element));36 }37 38 public void waitForTextToBePresentInElement(WebElement element, String text) {39 wait.until(ExpectedConditions.or(ExpectedConditions.textToBePresentInElement(element, text),40 ExpectedConditions.textToBePresentInElementValue(element, text)));41 }42 43 public void waitForPageToLoad() {44 45 fluentWait.until(new Predicate<WebDriver>() {46 47 @Override48 public boolean apply(WebDriver driver) {49 // TODO Auto-generated method stub50 return js.executeScript("return document.readyState").equals("complete");51 }52 });53 54 }55}...

Full Screen

Full Screen

Source:Waits.java Github

copy

Full Screen

1package org.sample;2import java.util.List;3import java.util.concurrent.TimeUnit;4import org.openqa.selenium.By;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.chrome.ChromeDriver;8import org.openqa.selenium.support.ui.ExpectedConditions;9import org.openqa.selenium.support.ui.FluentWait;10import org.openqa.selenium.support.ui.Select;11import org.openqa.selenium.support.ui.Wait;12import org.openqa.selenium.support.ui.WebDriverWait;13public class Waits {14 public static void main(String[] args) {15 16 System.setProperty("webdriver.chrome.driver", "C:\\\\Users\\\\Balachandar\\\\java & selenium\\\\Selenium\\\\driver\\\\chromedriver.exe");17 WebDriver driver=new ChromeDriver();18 19 driver.get("https://www.linkedin.com/signup/cold-join?session_redirect=https%3A%2F%2Fwww%2Elinkedin%2Ecom%2Ffeed%2F%3Ftrk%3Dnav_logo&trk=login_reg_redirect");20 21 driver.manage().window().maximize();22 23 //Implicity Wait24 driver.manage().timeouts().implicitlyWait(5000, TimeUnit.MICROSECONDS);25 26 WebElement textUser = driver.findElement(By.name("email-or-phone"));27 textUser.sendKeys("bala123@gmail.com");28 29 // WebDriver Wait30 31 WebDriverWait w = new WebDriverWait(driver, 5);32 WebElement until = w.until(ExpectedConditions.visibilityOfElementLocated(By.id("password")));33 until.sendKeys("bala@123");34 35 //Fluent Wait36 Wait w1=new FluentWait(driver).withTimeout(50, TimeUnit.SECONDS).pollingEvery(10, TimeUnit.SECONDS).ignoring(Throwable.class);37 Object u = w1.until(ExpectedConditions.elementToBeClickable(By.id("join-form-submit")));38 WebElement p=(WebElement)u;39 p.click();40 41 }42}...

Full Screen

Full Screen

or

Using AI Code Generation

copy

Full Screen

1ExpectedConditions.elementToBeClickable(By.id("myId"));2ExpectedConditions.elementToBeClickable(By.cssSelector("#myId"));3ExpectedConditions.elementToBeClickable(By.name("myName"));4ExpectedConditions.elementToBeClickable(By.className("myClass"));5ExpectedConditions.elementToBeClickable(By.tagName("div"));6ExpectedConditions.elementToBeClickable(By.linkText("myLinkText"));7ExpectedConditions.elementToBeClickable(By.partialLinkText("myPartialLinkText"));8ExpectedConditions.elementToBeClickable(WebElement element);9ExpectedConditions.elementToBeClickable(By by);10ExpectedConditions.elementToBeClickable(By.id("myId"));11ExpectedConditions.elementToBeClickable(By.cssSelector("#myId"));12ExpectedConditions.elementToBeClickable(By.name("myName"));13ExpectedConditions.elementToBeClickable(By.className("myClass"));14ExpectedConditions.elementToBeClickable(By.tagName("div"));15ExpectedConditions.elementToBeClickable(By.linkText("myLinkText"));16ExpectedConditions.elementToBeClickable(By.partialLinkText("myPartialLinkText"));17ExpectedConditions.elementToBeClickable(WebElement element);18ExpectedConditions.elementToBeClickable(By.id("myId"));19ExpectedConditions.elementToBeClickable(By.cssSelector("#myId"));20ExpectedConditions.elementToBeClickable(By.name("myName"));21ExpectedConditions.elementToBeClickable(By.className("myClass"));22ExpectedConditions.elementToBeClickable(By.tagName("div"));23ExpectedConditions.elementToBeClickable(By.linkText("myLinkText"));24ExpectedConditions.elementToBeClickable(By.partialLinkText("myPartialLinkText"));25ExpectedConditions.elementToBeClickable(WebElement element);26ExpectedConditions.elementToBeClickable(By.id("myId"));27ExpectedConditions.elementToBeClickable(By.cssSelector("#myId"));28ExpectedConditions.elementToBeClickable(By.name("myName"));29ExpectedConditions.elementToBeClickable(By.className("myClass"));.selenium.support.ui.ExpectedConditions class30ExdectedCondie ons.elementTtBeClickable(By.partialLiokText("myPartialLinkText"));31ExpectedConditions.elementToBeClickable(WebElement element);32ExpectedCondituons.elementToBeClickable(By.id("myId"));33System.out.println("Text of the element: " + element.getText());

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful