Best SeLion code snippet using com.paypal.selion.platform.html.AbstractElement.AbstractElement
Source:AbstractElement.java
...53import com.paypal.test.utilities.logging.SimpleLogger;54/**55 * Abstract element class for web elements.56 */57public abstract class AbstractElement implements Clickable, Hoverable {58 private static final String ALERTS_ARE_NOT_SUPPORTED_ERR_MSG = "Alerts are not supported in iPhone/iPad/PhantomJS as of 2.39.0.";59 private String locator;60 private String controlName;61 private ParentTraits parent;62 private final Map<String, String> propMap = new HashMap<String, String>();63 protected static final String LOG_DEMARKER = "→";64 private static SimpleLogger logger = SeLionLogger.getLogger();65 protected void setParent(ParentTraits parent) {66 this.parent = parent;67 }68 private final ElementEventListener dispatcher = (ElementEventListener) Proxy.newProxyInstance(69 ElementEventListener.class.getClassLoader(), new Class[] { ElementEventListener.class },70 new InvocationHandler() {71 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {72 try {73 List<ElementEventListener> eventListeners = Grid.getTestSession().getElementEventListeners();74 for (ElementEventListener eventListener : eventListeners) {75 method.invoke(eventListener, args);76 }77 return null;78 } catch (InvocationTargetException e) {79 throw e.getTargetException();80 }81 }82 });83 protected ElementEventListener getDispatcher() {84 return dispatcher;85 }86 /**87 * Instance method used to call static class method locateElement.88 *89 * @return the web element found by locator90 */91 public RemoteWebElement getElement() {92 RemoteWebElement foundElement = null;93 try {94 if (parent == null) {95 foundElement = HtmlElementUtils.locateElement(getLocator());96 } else {97 foundElement = parent.locateChildElement(locator);98 }99 } catch (ParentNotFoundException p) {100 throw p;101 } catch (NoSuchElementException n) {102 addInfoForNoSuchElementException(n);103 }104 return foundElement;105 }106 /**107 * Instance method used to call static class method locateElements.108 *109 * @return the list of web elements found by locator110 */111 public List<WebElement> getElements() {112 List<WebElement> foundElements = null;113 try {114 if (parent == null) {115 foundElements = HtmlElementUtils.locateElements(getLocator());116 } else {117 foundElements = parent.locateChildElements(getLocator());118 }119 } catch (NoSuchElementException n) {120 addInfoForNoSuchElementException(n);121 }122 return foundElements;123 }124 /**125 * A utility method to provide additional information to the user when a NoSuchElementException is thrown.126 *127 * @param cause128 * The associated cause for the exception.129 */130 private void addInfoForNoSuchElementException(NoSuchElementException cause) {131 if (parent == null) {132 throw cause;133 }134 BasicPageImpl page = this.parent.getCurrentPage();135 if (page == null) {136 throw cause;137 }138 String resolvedPageName = page.getClass().getSimpleName();139 // Find if page exists: This part is reached after a valid page instance is assigned to page variable. So its140 // safe to proceed!141 boolean pageExists = page.hasExpectedPageTitle();142 if (!pageExists) {143 // ParentType: Page does not exist: Sending the cause along with it144 throw new ParentNotFoundException(resolvedPageName + " : With Page Title {" + page.getActualPageTitle()145 + "} Not Found.", cause);146 }147 // The page exists. So lets prepare a detailed error message before throwing the exception.148 StringBuilder msg = new StringBuilder("Unable to find webElement ");149 if (this.controlName != null) {150 msg.append(this.controlName).append(" on ");151 }152 if (resolvedPageName != null) {153 msg.append(resolvedPageName);154 }155 msg.append(" using the locator {").append(locator).append("}");156 throw new NoSuchElementException(msg.toString(), cause);157 }158 /**159 * Constructs an AbstractElement with locator.160 *161 * @param locator162 */163 public AbstractElement(String locator) {164 this.locator = locator;165 }166 /**167 * Constructs an AbstractElement with locator and parent.168 *169 * @param parent170 * A {@link ParentTraits} object that represents the parent element for this element.171 * @param locator172 * A String that represents the means to locate this element (could be id/name/xpath/css locator).173 */174 public AbstractElement(ParentTraits parent, String locator) {175 this.parent = parent;176 this.locator = locator;177 }178 /**179 * Constructs an AbstractElement with locator and controlName.180 *181 * @param locator182 * the element locator183 * @param controlName184 * the control name used for logging185 */186 public AbstractElement(String locator, String controlName) {187 this(locator, controlName, null);188 }189 /**190 * Constructs an AbstractElement with locator, parent, and controlName.191 *192 * @param locator193 * A String that represents the means to locate this element (could be id/name/xpath/css locator).194 * @param controlName195 * the control name used for logging196 * @param parent197 * A {@link ParentTraits} object that represents the parent element for this element.198 */199 public AbstractElement(String locator, String controlName, ParentTraits parent) {200 this.locator = locator;201 this.parent = parent;202 this.controlName = controlName;203 }204 /**205 * Retrieves the locator (id/name/xpath/css locator) for the current {@link AbstractElement} element.206 *207 * @return The value of locator.208 */209 public String getLocator() {210 return locator;211 }212 /**213 * Retrieves the control name for the current {@link AbstractElement} element.214 *215 * @return The value of controlName.216 */217 public String getControlName() {218 return controlName;219 }220 /**221 * Retrieves the parent element for the current {@link AbstractElement} element.222 *223 * @return A {@link ParentTraits} that represents the parent of the current {@link AbstractElement} element.224 */225 public ParentTraits getParent() {226 return parent;227 }228 /**229 * Finds element on the page and returns the visible (i.e. not hidden by CSS) innerText of this element, including230 * sub-elements, without any leading or trailing whitespace.231 *232 * @return The innerText of this element.233 */234 public String getText() {235 return getElement().getText();236 }237 /**238 * Checks if element is present in the html dom. An element that is present in the html dom does not mean it is239 * visible. To check if element is visible, use {@link #getElement()} to get {@link WebElement} and then invoke240 * {@link WebElement#isDisplayed()}.241 *242 * @return True if element is present, false otherwise.243 */244 public boolean isElementPresent() {245 logger.entering();246 boolean returnValue = false;247 try {248 if (getElement() != null) {249 returnValue = true;250 }251 } catch (NoSuchElementException e) {252 returnValue = false;253 }254 logger.exiting(returnValue);255 return returnValue;256 }257 /**258 * Is this element displayed or not? This method avoids the problem of having to parse an element's "style"259 * attribute.260 *261 * @return Whether or not the element is displayed262 */263 public boolean isVisible() {264 return getElement().isDisplayed();265 }266 /**267 * Is the element currently enabled or not? This will generally return true for everything but disabled input268 * elements.269 *270 * @return True if element is enabled, false otherwise.271 */272 public boolean isEnabled() {273 return getElement().isEnabled();274 }275 /**276 * Get the value of a the given attribute of the element. Will return the current value, even if this has been277 * modified after the page has been loaded. More exactly, this method will return the value of the given attribute,278 * unless that attribute is not present, in which case the value of the property with the same name is returned. If279 * neither value is set, null is returned. The "style" attribute is converted as best can be to a text280 * representation with a trailing semi-colon. The following are deemed to be "boolean" attributes, and will return281 * either "true" or null: async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked,282 * defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate, iscontenteditable,283 * ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open, paused, pubdate,284 * readonly, required, reversed, scoped, seamless, seeking, selected, spellcheck, truespeed, willvalidate. Finally,285 * the following commonly mis-capitalized attribute/property names are evaluated as expected: class, readonly286 *287 *288 * @param attributeName289 * the attribute name to get current value290 * @return The attribute's current value or null if the value is not set.291 */292 public String getAttribute(String attributeName) {293 return getElement().getAttribute(attributeName);294 }295 /**296 * Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter). For297 * checkbox/radio elements, the value will be "on" or "off" depending on whether the element is checked or not.298 *299 * @return the element value, or "on/off" for checkbox/radio elements300 */301 public String getValue() {302 return getAttribute("value");303 }304 /**305 * Gets value from property map {@link #propMap}.306 *307 * @param key308 * the key to retrieve a value from the property map309 * @return the value to which the specified key is mapped, or null if this map contains no mapping for the key310 */311 public String getProperty(String key) {312 return propMap.get(key);313 }314 /**315 * Sets value in property map {@link #propMap}.316 *317 * @param key318 * @param value319 */320 public void setProperty(String key, String value) {321 propMap.put(key, value);322 }323 protected String getWaitTime() {324 return ConfigManager.getConfig(Grid.getTestSession().getXmlTestName()).getConfigProperty(325 ConfigProperty.EXECUTION_TIMEOUT);326 }327 protected String resolveControlNameToUseForLogs() {328 String resolvedName = getControlName();329 if (resolvedName == null) {330 return getLocator();331 }332 return resolvedName;333 }334 protected void logUIAction(UIActions actionPerformed) {335 logUIActions(actionPerformed, null);336 }337 protected void logUIActions(UIActions actionPerformed, String value) {338 logger.entering(new Object[] { actionPerformed, value });339 String valueToUse = (value == null) ? "" : value + " in ";340 Reporter.log(LOG_DEMARKER + actionPerformed.getAction() + valueToUse + resolveControlNameToUseForLogs(), false);341 logger.exiting();342 }343 protected void processScreenShot() {344 logger.entering();345 processAlerts(Grid.getWebTestSession().getBrowser());346 dispatcher.beforeScreenshot(this);347 String title = "Default Title";348 try {349 title = Grid.driver().getTitle();350 } catch (WebDriverException thrown) { // NOSONAR351 logger.log(Level.FINER, "An exception occurred while getting page title", thrown);352 }353 boolean logPages = Boolean.parseBoolean(Config.getConfigProperty(ConfigProperty.LOG_PAGES));354 if (Boolean.parseBoolean(Config.getConfigProperty(ConfigProperty.AUTO_SCREEN_SHOT))) {355 SeLionReporter.log(title, true, logPages);356 } else {357 SeLionReporter.log(title, false, logPages);358 }359 dispatcher.afterScreenshot(this);360 logger.exiting();361 }362 private void processAlerts(String browser) {363 logger.entering(browser);364 if (doesNotHandleAlerts(browser)) {365 logger.exiting(ALERTS_ARE_NOT_SUPPORTED_ERR_MSG);366 return;367 }368 try {369 Grid.driver().switchTo().alert();370 logger.warning("Encountered an alert. Skipping processing of screenshots");371 logger.exiting();372 return;373 } catch (NoAlertPresentException exception) {374 // Gobble the exception and do nothing with it. No alert was triggered. So it is safe to proceed with taking375 // screenshots.376 }377 }378 private boolean doesNotHandleAlerts(String browserFlavor) {379 logger.entering(browserFlavor);380 BrowserFlavors browser = BrowserFlavors.getBrowser(browserFlavor);381 boolean returnValue = Arrays.asList(BrowserFlavors.getBrowsersWithoutAlertSupport()).contains(browser);382 logger.exiting(returnValue);383 return returnValue;384 }385 protected void validatePresenceOfAlert() {386 String browser = Grid.getWebTestSession().getBrowser();387 logger.finest("Validating presence of alert with browser " + browser);388 if (doesNotHandleAlerts(browser)) {389 logger.info(ALERTS_ARE_NOT_SUPPORTED_ERR_MSG);390 return;391 }392 try {393 Grid.driver().switchTo().alert();394 String errorMsg = "Encountered an alert. Cannot wait for an element when an operation triggers an alert.";395 throw new InvalidElementStateException(errorMsg);396 } catch (NoAlertPresentException exception) {397 // Gobble the exception and do nothing with it. No alert was triggered. So it is safe to proceed ahead.398 }399 }400 /**401 * Basic click event on the Element. Functionally equivalent to {@link #clickonly()}402 */403 public void click() {404 clickonly();405 }406 /**407 * Basic click event on the Element. Doesn't wait for anything to load.408 *409 */410 public void clickonly() {411 click(new Object[] {});412 }413 /**414 * The click function and wait for expected {@link Object} items to load.415 *416 * @param expected417 * parameters in the form of an element locator {@link String}, a {@link WebPage}, an418 * {@link AbstractElement}, or an {@link ExpectedCondition}419 */420 @SuppressWarnings("unchecked")421 public void click(Object... expected) {422 dispatcher.beforeClick(this, expected);423 getElement().click();424 if (Boolean.parseBoolean(Config.getConfigProperty(ConfigProperty.ENABLE_GUI_LOGGING))) {425 logUIAction(UIActions.CLICKED);426 }427 // If there are no expected objects, then it means user wants this428 // method to behave as a clickonly. So lets skip processing of alerts and leave429 // that to the user.430 if (expected == null || expected.length == 0) {431 return;432 }433 if (parent != null) {434 WebDriverWaitUtils.waitUntilPageIsLoaded(parent.getCurrentPage());435 }436 validatePresenceOfAlert();437 try {438 for (Object expect : expected) {439 if (expect instanceof AbstractElement) {440 AbstractElement a = (AbstractElement) expect;441 WebDriverWaitUtils.waitUntilElementIsPresent(a.getLocator());442 continue;443 }444 if (expect instanceof String) {445 String s = (String) expect;446 WebDriverWaitUtils.waitUntilElementIsPresent(s);447 continue;448 }449 if (expect instanceof ExpectedCondition<?>) {450 long timeOutInSeconds = Grid.getExecutionTimeoutValue() / 1000;451 WebDriverWait wait = new WebDriverWait(Grid.driver(), timeOutInSeconds);452 wait.until(ExpectedCondition.class.cast(expect));453 continue;454 }455 if (expect instanceof WebPage) {456 WebDriverWaitUtils.waitUntilPageIsValidated((WebPage) expect);457 continue;458 }459 }460 } finally {461 // Attempt at taking screenshots even when there are time-outs triggered from the wait* methods.462 processScreenShot();463 dispatcher.afterClick(this, expected);464 }465 }466 /**467 * The click function and wait based on the ExpectedCondition.468 *469 * @param expectedCondition470 * ExpectedCondition<?> instance to be passed.471 *472 * @return The return value of473 * {@link org.openqa.selenium.support.ui.FluentWait#until(com.google.common.base.Function)} if the function474 * returned something different from null or false before the timeout expired.<br>475 *476 * <pre>477 * Grid.driver().get("https://www.paypal.com");478 * TextField userName = new TextField("login_email");479 * TextField password = new TextField("login_password");480 * Button btn = new Button("submit.x");481 *482 * userName.type("exampleId@paypal.com");483 * password.type("123Abcde");484 * btn.clickAndExpect(ExpectedConditions.titleIs("MyAccount - PayPal"));485 * </pre>486 */487 public Object clickAndExpect(ExpectedCondition<?> expectedCondition) {488 dispatcher.beforeClick(this, expectedCondition);489 getElement().click();490 if (Boolean.parseBoolean(Config.getConfigProperty(ConfigProperty.ENABLE_GUI_LOGGING))) {491 logUIAction(UIActions.CLICKED);492 }493 if (parent != null) {494 WebDriverWaitUtils.waitUntilPageIsLoaded(parent.getCurrentPage());495 }496 validatePresenceOfAlert();497 long timeout = Grid.getExecutionTimeoutValue() / 1000;498 WebDriverWait wait = new WebDriverWait(Grid.driver(), timeout);499 Object variable = wait.until(expectedCondition);500 processScreenShot();501 dispatcher.afterClick(this, expectedCondition);502 return variable;503 }504 /**505 * Click function that will wait for one of the ExpectedConditions to match.506 * {@link org.openqa.selenium.TimeoutException} exception will be thrown if no conditions are matched within the507 * allowed time {@link ConfigProperty#EXECUTION_TIMEOUT}508 *509 * @param conditions510 * {@link List}<{@link ExpectedCondition}<?>> of supplied conditions passed.511 * @return first {@link org.openqa.selenium.support.ui.ExpectedCondition} that was matched512 */513 public ExpectedCondition<?> clickAndExpectOneOf(final List<ExpectedCondition<?>> conditions) {514 dispatcher.beforeClick(this, conditions);515 getElement().click();516 if (Boolean.parseBoolean(Config.getConfigProperty(ConfigProperty.ENABLE_GUI_LOGGING))) {517 logUIAction(UIActions.CLICKED);518 }519 // If there are no expected objects, then it means user wants this method520 // to behave as a clickonly. So lets skip processing of alerts and leave521 // that to the user.522 if (conditions == null || conditions.size() <= 0) {523 return null;524 }525 if (parent != null) {526 WebDriverWaitUtils.waitUntilPageIsLoaded(parent.getCurrentPage());527 }528 validatePresenceOfAlert();529 long timeout = Grid.getExecutionTimeoutValue() / 1000;530 try {531 WebDriverWait wait = new WebDriverWait(Grid.driver(), timeout);532 wait.ignoring(NoSuchElementException.class);533 wait.ignoring(ExpectOneOfException.class);534 ExpectedCondition<?> matchedCondition = wait.until(new Function<WebDriver, ExpectedCondition<?>>() {535 // find the first condition that matches and return it536 @Override537 public ExpectedCondition<?> apply(WebDriver webDriver) {538 StringBuilder sb = new StringBuilder();539 int i = 1;540 for (final ExpectedCondition<?> condition : conditions) {541 try {542 Object value = condition.apply(webDriver);543 if (value instanceof Boolean) {544 if (Boolean.TRUE.equals(value)) {545 return condition;546 }547 } else if (value != null) {548 return condition;549 }550 } catch (WebDriverException e) {551 sb.append("\n\tObject " + i + ":\n");552 sb.append("\t" + ExceptionUtils.getRootCauseMessage(e).split("\n")[0] + "\n");553 sb.append("\t\t" + StringUtils.substringBetween(ExceptionUtils.getStackTrace(e), "\n"));554 }555 i++;556 }557 throw new ExpectOneOfException(sb.toString());558 }559 });560 return matchedCondition;561 } finally {562 // Attempt at taking screenshots even when there are time-outs triggered from the wait* methods.563 processScreenShot();564 dispatcher.afterClick(this, conditions);565 }566 }567 /**568 * The click function and wait for one of the expected {@link Object} items to load.569 *570 * @param expected571 * parameters in the form of an element locator {@link String}, a {@link WebPage}, or an572 * {@link AbstractElement}573 * @return the first object that was matched574 */575 public Object clickAndExpectOneOf(final Object... expected) {576 dispatcher.beforeClick(this, expected);577 getElement().click();578 if (Boolean.parseBoolean(Config.getConfigProperty(ConfigProperty.ENABLE_GUI_LOGGING))) {579 logUIAction(UIActions.CLICKED);580 }581 // If there are no expected objects, then it means user wants this method582 // to behave as a clickonly. So lets skip processing of alerts and leave583 // that to the user.584 if (expected == null || expected.length == 0) {585 return null;586 }587 if (parent != null) {588 WebDriverWaitUtils.waitUntilPageIsLoaded(parent.getCurrentPage());589 }590 validatePresenceOfAlert();591 long timeout = Grid.getExecutionTimeoutValue() / 1000;592 try {593 WebDriverWait wait = new WebDriverWait(Grid.driver(), timeout);594 wait.ignoring(NoSuchElementException.class);595 wait.ignoring(PageValidationException.class);596 Object expectedObj = wait.ignoring(ExpectOneOfException.class).until(new Function<WebDriver, Object>() {597 // find the first object that is matched and return it598 @Override599 public Object apply(WebDriver webDriver) {600 StringBuilder sb = new StringBuilder();601 int i = 1;602 for (Object expect : expected) {603 try {604 if (expect instanceof AbstractElement) {605 AbstractElement element = (AbstractElement) expect;606 if (HtmlElementUtils.locateElement(element.getLocator()) != null) {607 return expect;608 }609 } else if (expect instanceof String) {610 String s = (String) expect;611 if (HtmlElementUtils.locateElement(s) != null) {612 return expect;613 }614 } else if (expect instanceof WebPage) {615 WebPage w = (WebPage) expect;616 w.validatePage();617 return expect;618 }619 } catch (NoSuchElementException | PageValidationException e) { // NOSONAR620 sb.append("\n\tObject " + i + ": " + expect.getClass().getSimpleName() + "\n");621 sb.append("\t" + ExceptionUtils.getRootCauseMessage(e) + "\n");622 sb.append("\t\t" + StringUtils.substringBetween(ExceptionUtils.getStackTrace(e), "\n"));623 }624 i++;625 }626 throw new ExpectOneOfException(sb.toString());627 }628 });629 return expectedObj;630 } finally {631 // Attempt at taking screenshots even when there are time-outs triggered from the wait* methods.632 processScreenShot();633 dispatcher.afterClick(this, expected);634 }635 }636 /**637 * Moves the mouse pointer to the middle of the element. And waits for the expected elements to be visible.638 *639 * @param expected640 * parameters in the form of an element locator {@link String} or an {@link AbstractElement}641 */642 public void hover(final Object... expected) {643 dispatcher.beforeHover(this, expected);644 new Actions(Grid.driver()).moveToElement(getElement()).perform();645 try {646 for (Object expect : expected) {647 if (expect instanceof AbstractElement) {648 AbstractElement a = (AbstractElement) expect;649 WebDriverWaitUtils.waitUntilElementIsVisible(a.getLocator());650 } else if (expect instanceof String) {651 String s = (String) expect;652 WebDriverWaitUtils.waitUntilElementIsVisible(s);653 }654 }655 } finally {656 processScreenShot();657 dispatcher.afterHover(this, expected);658 }659 }660}...
Source:ExpediaDatePicker.java
1package ExpediaTestTravel.ExpediaTestTravel;2import java.util.Calendar;3import java.util.Date;4import com.paypal.selion.platform.html.AbstractElement;5import com.paypal.selion.platform.html.ParentTraits;6import com.paypal.selion.platform.html.support.HtmlElementUtils;7/**8 * Date Picker using custom Selion Element9 * @author mousumisen10 *11 */12public class ExpediaDatePicker extends AbstractElement {13 private String nextMonthLocator;14 public ExpediaDatePicker(ParentTraits parent, String locator) {15 super(parent, locator);16 initDateWidgetLocators();17 }18 public ExpediaDatePicker(String locator, String controlName,19 ParentTraits parent) {20 super(locator, controlName, parent);21 initDateWidgetLocators();22 }23 public ExpediaDatePicker(String locator, String controlName) {24 super(locator, controlName);25 initDateWidgetLocators();26 }...
AbstractElement
Using AI Code Generation
1package com.paypal.selion.testcomponents;2import com.paypal.selion.platform.html.AbstractElement;3import com.paypal.selion.platform.html.Button;4import com.paypal.selion.platform.html.CheckBox;5import com.paypal.selion.platform.html.Element;6import com.paypal.selion.platform.html.Label;7import com.paypal.selion.platform.html.Link;8import com.paypal.selion.platform.html.PageElement;9import com.paypal.selion.platform.html.RadioButton;10import com.paypal.selion.platform.html.SelectList;11import com.paypal.selion.platform.html.Table;12import com.paypal.selion.platform.html.TextArea;13import com.paypal.selion.platform.html.TextField;14import com.paypal.selion.platform.html.WebPage;15public class Page3 extends WebPage {16 private static final String PAGE_TITLE = "Page3";17 private static final String PAGE_URL = "page3.html";18 private static final String PAGE_FRAME = "frame3";19 public Page3() {20 super(PAGE_TITLE, PAGE_URL, PAGE_FRAME);21 }22 public Page3(String title, String url, String frame) {23 super(title, url, frame);24 }25 public Button getButton() {26 }27 public CheckBox getCheckBox() {28 }29 public Label getLabel() {30 }31 public Link getLink() {32 }33 public RadioButton getRadioButton() {34 }35 public SelectList getSelectList() {36 }37 public Table getTable() {38 }39 public TextArea getTextArea() {40 }41 public TextField getTextField() {42 }43}44package com.paypal.selion.testcomponents;45import com.paypal.selion.platform.html.AbstractElement;46import com.paypal.selion.platform.html.Button;47import com.paypal.selion.platform.html.CheckBox;48import com.paypal.selion.platform.html.Element;49import com.paypal.selion.platform.html.Label;50import com.paypal.selion.platform.html.Link;51import com.paypal.selion.platform
AbstractElement
Using AI Code Generation
1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.firefox.FirefoxDriver;5import com.paypal.selion.platform.html.AbstractElement;6public class 3 {7 public static void main(String[] args) throws InterruptedException {8 WebDriver driver = new FirefoxDriver();9 WebElement element = driver.findElement(By.id("gbqfq"));10 AbstractElement.checkDisabled(element);11 AbstractElement.checkEnabled(element);12 driver.quit();13 }14}15import org.openqa.selenium.By;16import org.openqa.selenium.WebDriver;17import org.openqa.selenium.WebElement;18import org.openqa.selenium.firefox.FirefoxDriver;19import com.paypal.selion.platform.html.AbstractElement;20public class 4 {21 public static void main(String[] args) throws InterruptedException {22 WebDriver driver = new FirefoxDriver();23 WebElement element = driver.findElement(By.id("gbqfq"));24 AbstractElement.checkEnabled(element);25 AbstractElement.checkDisabled(element);26 driver.quit();27 }28}29import org.openqa.selenium.By;30import org.openqa.selenium.WebDriver;31import org.openqa.selenium.WebElement;32import org.openqa.selenium.firefox.FirefoxDriver;33import com.paypal.selion.platform.html.AbstractElement;34public class 5 {35 public static void main(String[] args) throws InterruptedException {36 WebDriver driver = new FirefoxDriver();37 WebElement element = driver.findElement(By.id("gbqfq"));38 AbstractElement.checkDisplayed(element);39 AbstractElement.checkNotDisplayed(element);40 driver.quit();41 }42}43import org.openqa.selenium.By;44import org.openqa.selenium.WebDriver;45import
AbstractElement
Using AI Code Generation
1package com.paypal.selion.tutorials;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.support.FindBy;6import org.openqa.selenium.support.How;7import org.openqa.selenium.support.PageFactory;8import org.testng.annotations.BeforeTest;9import org.testng.annotations.Test;10import com.paypal.selion.platform.html.AbstractElement;11import com.paypal.selion.platform.html.Button;12import com.paypal.selion.platform.html.Label;13import com.paypal.selion.platform.html.TextField;14public class AbstractElementTutorial {15 private WebDriver driver;16 @FindBy(how = How.NAME, using = "q")17 private WebElement searchBox;18 @FindBy(how = How.NAME, using = "btnK")19 private WebElement searchButton;20 @FindBy(how = How.NAME, using = "btnI")21 private WebElement feelingLuckyButton;22 @FindBy(how = How.ID, using = "resultStats")23 private WebElement searchResultLabel;24 private TextField searchBoxElement;25 private Button searchButtonElement;26 private Button feelingLuckyButtonElement;27 private Label searchResultLabelElement;28 public void initialize() {29 driver = new ChromeDriver();30 driver.get(url);31 PageFactory.initElements(driver, this);32 searchBoxElement = new TextField(searchBox);33 searchButtonElement = new Button(searchButton);34 feelingLuckyButtonElement = new Button(feelingLuckyButton);35 searchResultLabelElement = new Label(searchResultLabel);36 }37 public void testAbstractElement() {38 String searchBoxValue = searchBoxElement.getAttribute("value");39 System.out.println("The value of the search box is: " + searchBoxValue);40 }41}
AbstractElement
Using AI Code Generation
1public class 3 extends AbstractTest{2 public static void main(String[] args) {3 SeLionGridLauncher.main(new String[] { "nodeConfig=src/main/resources/nodeConfig.json" });4 page.open();5 page.getHtmlElement("name", "q").setText("SeLion");6 page.getHtmlElement("name", "btnG").click();7 page.getHtmlElement("linkText", "SeLion - Web Testing Framework").click();8 page.getHtmlElement("linkText", "SeLion").click();9 page.getHtmlElement("linkText", "Downloa
AbstractElement
Using AI Code Generation
1AbstractElement abstractElement = new AbstractElement(element);2abstractElement.isDisplayed();3AbstractElement abstractElement = new AbstractElement(element);4abstractElement.isEnabled();5AbstractElement abstractElement = new AbstractElement(element);6abstractElement.isSelected();7AbstractElement abstractElement = new AbstractElement(element);8abstractElement.isVisible();9AbstractElement abstractElement = new AbstractElement(element);10abstractElement.isStale();11AbstractElement abstractElement = new AbstractElement(element);12abstractElement.isStale();13AbstractElement abstractElement = new AbstractElement(element);14abstractElement.isStale();15AbstractElement abstractElement = new AbstractElement(element);16abstractElement.isStale();17WebElement element = driver.findElement(By
AbstractElement
Using AI Code Generation
1package com.paypal.selion.platform.html.support;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.support.ui.WebDriverWait;7import org.testng.Assert;8import org.testng.annotations.AfterClass;9import org.testng.annotations.BeforeClass;10import org.testng.annotations.Test;11public class AbstractElementTest {12 private WebDriver driver;13 private WebElement element;14 private WebDriverWait wait;15 private static final String elementId = "lst-ib";16 public void setup() {17 driver = new ChromeDriver();18 wait = new WebDriverWait(driver, 20);19 driver.get(url);20 element = driver.findElement(By.id(elementId));21 }22 public void tearDown() {23 driver.quit();24 }25 public void testIsElementDisplayed() {26 Assert.assertTrue(AbstractElement.isElementDisplayed(element));27 }28}29package com.paypal.selion.platform.html.support;30import org.openqa.selenium.By;31import org.openqa.selenium.WebDriver;32import org.openqa.selenium.WebElement;33import org.openqa.selenium.chrome.ChromeDriver;34import org.openqa.selenium.support.ui.WebDriverWait;35import org.testng.Assert;36import org.testng.annotations.AfterClass;37import org.testng.annotations.BeforeClass;38import org.testng.annotations.Test;39public class AbstractElementTest {40 private WebDriver driver;41 private WebElement element;42 private WebDriverWait wait;43 private static final String elementId = "lst-ib";44 public void setup() {45 driver = new ChromeDriver();46 wait = new WebDriverWait(driver, 20);47 driver.get(url);48 element = driver.findElement(By.id(elementId));49 element.clear();50 }51 public void tearDown() {52 driver.quit();53 }54 public void testIsElementDisplayed() {55 Assert.assertFalse(AbstractElement.isElementDisplayed(element));56 }57}
AbstractElement
Using AI Code Generation
1package com.paypal.selion.testcomponents;2import com.paypal.selion.platform.html.AbstractElement;3import com.paypal.selion.platform.html.TextField;4import com.paypal.selion.platform.utilities.WebDriverWaitUtils;5import org.openqa.selenium.support.FindBy;6public class LoginPage {7@FindBy(id = "email")8private TextField email;9public void waitForPageToLoad() {10WebDriverWaitUtils.waitUntilElementIsVisible(email);11}12public String getLoginEmailClass() {13return email.getAttribute("class");14}15}16package com.paypal.selion.testcomponents;17import com.paypal.selion.platform.html.AbstractElement;18import com.paypal.selion.platform.html.TextField;19import com.paypal.selion.platform.utilities.WebDriverWaitUtils;20import org.openqa.selenium.support.FindBy;21public class LoginPage {22@FindBy(id = "email")23private TextField email;24public void waitForPageToLoad() {25WebDriverWaitUtils.waitUntilElementIsVisible(email);26}27public String getLoginEmailClass() {28return email.getAttribute("class");29}30}31package com.paypal.selion.testcomponents;32import com.paypal.selion.platform.html.AbstractElement;33import com.paypal.selion.platform.html.TextField;34import com.paypal.selion.platform.utilities.WebDriverWaitUtils;35import org.openqa.selenium.support.FindBy;36public class LoginPage {37@FindBy(id = "email")38private TextField email;39public void waitForPageToLoad() {40WebDriverWaitUtils.waitUntilElementIsVisible(email);41}42public String getLoginEmailClass() {43return email.getAttribute("class");44}45}46package com.paypal.selion.testcomponents;47import com.paypal.selion.platform.html.AbstractElement;48import com.pay
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!