How to use Interface WebElement class of org.openqa.selenium package

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

Source:ListboxImpl.java Github

copy

Full Screen

1package com.orasi.core.interfaces.impl;2import java.util.List;3import org.openqa.selenium.By;4import org.openqa.selenium.NoSuchElementException;5import org.openqa.selenium.WebElement;6import com.orasi.core.interfaces.Listbox;7import com.orasi.exception.automation.OptionNotInListboxException;8import com.orasi.utils.OrasiDriver;9import com.orasi.utils.TestReporter;10/**11 * Wrapper around a WebElement for the Select class in Selenium.12 */13public class ListboxImpl extends ElementImpl implements Listbox {14 private final org.openqa.selenium.support.ui.Select innerSelect;15 /**16 * @summary - Wraps a WebElement with listbox functionality.17 * @param element18 * - element to wrap up19 */20 public ListboxImpl(WebElement element) {21 super(element);22 this.innerSelect = new org.openqa.selenium.support.ui.Select(element);23 }24 public ListboxImpl(OrasiDriver driver, By by) {25 super(driver, by);26 // element = driver.findWebElement(by);27 TestReporter.logTrace("Entering ListboxImpl#init");28 this.innerSelect = new org.openqa.selenium.support.ui.Select(driver.findWebElement(by));29 TestReporter.logTrace("Exiting ListboxImpl#init");30 }31 /**32 * @summary - Wraps Selenium's method.33 * @param text34 * - visible text to select35 * @see org.openqa.selenium.support.ui.Select#selectByVisibleText(String)36 */37 @Override38 public void select(String text) {39 TestReporter.logTrace("Entering ListboxImpl#select");40 if (!text.isEmpty()) {41 try {42 try {43 innerSelect.selectByVisibleText(text);44 } catch (RuntimeException rte) {45 TestReporter.interfaceLog("Select option [ <b>" + text.toString()46 + "</b> ] from Listbox [ <b>" + getElementLocatorInfo() + " </b>]", true);47 throw rte;48 }49 TestReporter.interfaceLog("Select option [ <b>" + text.toString()50 + "</b> ] from Listbox [ <b>" + getElementLocatorInfo() + " </b>]");51 } catch (NoSuchElementException e) {52 String optionList = "";53 List<WebElement> optionsList = innerSelect.getOptions();54 for (WebElement option : optionsList) {55 optionList += option.getText() + " | ";56 }57 TestReporter.interfaceLog(" The value of <b>[ " + text + "</b> ] was not found in Listbox [ <b>"58 + getElementLocatorInfo() + " </b>]. Acceptable values are " + optionList + " ]");59 TestReporter.logTrace("Exiting ListboxImpl#select");60 throw new OptionNotInListboxException("The value of [ " + text + " ] was not found in Listbox [ "61 + getElementLocatorInfo() + " ]. Acceptable values are " + optionList, getWrappedDriver());62 }63 } else {64 TestReporter.interfaceLog("Skipping input to Textbox [ <b>" + getElementLocatorInfo() + " </b> ]");65 }66 TestReporter.logTrace("Exiting ListboxImpl#select");67 }68 /**69 * @summary - Wraps Selenium's method.70 * @param value71 * - option value to select72 * @see org.openqa.selenium.support.ui.Select#selectByVisibleText(String)73 */74 @Override75 public void selectValue(String value) {76 TestReporter.logTrace("Entering ListboxImpl#selectValue");77 if (!value.isEmpty()) {78 try {79 try {80 innerSelect.selectByValue(value);81 } catch (RuntimeException rte) {82 TestReporter.interfaceLog("Select option [ <b>" + value.toString()83 + "</b> ] from Listbox [ <b>" + getElementLocatorInfo() + " </b>]", true);84 throw rte;85 }86 TestReporter.interfaceLog("Select option [ <b>" + value.toString()87 + "</b> ] from Listbox [ <b>" + getElementLocatorInfo() + " </b>]");88 } catch (NoSuchElementException e) {89 String optionList = "";90 List<WebElement> optionsList = innerSelect.getOptions();91 for (WebElement option : optionsList) {92 optionList += option.getAttribute("value") + " | ";93 }94 TestReporter95 .interfaceLog(" The value of <b>[ " + value + "</b> ] was not found in Listbox [ <b>"96 + getElementLocatorInfo() + " </b>]. Acceptable values are " + optionList + " ]");97 TestReporter.logTrace("Exiting ListboxImpl#selectValue");98 throw new OptionNotInListboxException("The value of [ " + value + " ] was not found in Listbox [ "99 + getElementLocatorInfo() + " ]. Acceptable values are " + optionList, getWrappedDriver());100 }101 } else {102 TestReporter.interfaceLog("Skipping input to Textbox [ <b>" + getElementLocatorInfo() + " </b> ]");103 }104 TestReporter.logTrace("Exiting ListboxImpl#selectValue");105 }106 /**107 * @summary - Wraps Selenium's method.108 * @see org.openqa.selenium.support.ui.Select#deselectAll()109 */110 @Override111 public void deselectAll() {112 TestReporter.logTrace("Entering ListboxImpl#deselectAll");113 innerSelect.deselectAll();114 TestReporter.logTrace("Exiting ListboxImpl#deselectAll");115 }116 /**117 * @summary - Wraps Selenium's method.118 * @return list of all options in the select.119 * @see org.openqa.selenium.support.ui.Select#getOptions()120 */121 @Override122 public List<WebElement> getOptions() {123 TestReporter.logTrace("Entering ListboxImpl#getOptions");124 List<WebElement> options = innerSelect.getOptions();125 TestReporter.logTrace("Exiting ListboxImpl#getOptions");126 return options;127 }128 /**129 * @summary - Wraps Selenium's method.130 * @param text131 * text to deselect by visible text132 * @see org.openqa.selenium.support.ui.Select#deselectByVisibleText(String)133 */134 @Override135 public void deselectByVisibleText(String text) {136 TestReporter.logTrace("Entering ListboxImpl#deselectByVisibleText");137 innerSelect.deselectByVisibleText(text);138 TestReporter.logTrace("Exiting ListboxImpl#deselectByVisibleText");139 }140 /**141 * @summary - Wraps Selenium's method.142 * @return WebElement of the first selected option.143 * @see org.openqa.selenium.support.ui.Select#getFirstSelectedOption()144 */145 @Override146 public WebElement getFirstSelectedOption() {147 TestReporter.logTrace("Entering ListboxImpl#getFirstSelectedOption");148 try {149 WebElement option = innerSelect.getFirstSelectedOption();150 TestReporter.logTrace("Exiting ListboxImpl#deselectByVisibleText");151 return option;152 } catch (NoSuchElementException nse) {153 TestReporter.logTrace("Exiting ListboxImpl#deselectByVisibleText");154 return null;155 }156 }157 /**158 * @see org.openqa.selenium.WebElement#isSelected()159 */160 @Override161 public boolean isSelected(String option) {162 TestReporter.logTrace("Entering ListboxImpl#isSelected");163 List<WebElement> selectedOptions = innerSelect.getAllSelectedOptions();164 for (WebElement selectOption : selectedOptions) {165 if (selectOption.getText().equals(option)){166 TestReporter.logTrace("Exiting ListboxImpl#isSelected");167 return true;168 }169 }170 TestReporter.logTrace("Exiting ListboxImpl#isSelected");171 return false;172 }173 @Override174 public List<WebElement> getAllSelectedOptions() {175 TestReporter.logTrace("Entering ListboxImpl#getAllSelectedOptions");176 List<WebElement> options = innerSelect.getAllSelectedOptions();177 TestReporter.logTrace("Exiting ListboxImpl#getAllSelectedOptions");178 return options;179 }180 @Override181 public boolean isMultiple() {182 TestReporter.logTrace("Entering ListboxImpl#isMultiple");183 boolean multiple = innerSelect.isMultiple();184 TestReporter.logTrace("Exiting ListboxImpl#isMultiple");185 return multiple;186 }187}...

Full Screen

Full Screen

Source:ISelect.java Github

copy

Full Screen

1/**2 Copyright (c) 2011, Strata Health Solutions Inc.3 All rights reserved.4 Redistribution and use in source and binary forms, with or without modification, are permitted 5 provided that the following conditions are met:6 Redistributions of source code must retain the above copyright notice, this list of conditions 7 and the following disclaimer.8 Redistributions in binary form must reproduce the above copyright notice, this list of conditions 9 and the following disclaimer in the documentation and/or other materials provided with the distribution.10 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 11 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 12 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 13 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 14 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 15 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 16 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 17 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.18**/19package shelob.core.interfaces.webdriver;20import java.util.List;21import org.openqa.selenium.WebElement;22/**23 * @author melllaguno24 * @version $Revision: 1.0 $25 * 26 * The Select Utility Wrapper Interface for WebElements27 * 28 * @param <T> the fluent interface type29 */30public interface ISelect<T> {31 /**32 * @see org.openqa.selenium.WebElement.Select#isMultiple33 * @return boolean34 */35 boolean isMultiple();36 37 /**38 * Helper Method : wraps function with Wait39 * @return boolean40 */41 boolean isMultipleWhenVisible();42 /**43 * Helper Method : wraps function with Wait44 * @param waitTimeInSeconds45 * @return boolean46 */47 boolean isMultipleWhenVisible(int waitTimeInSeconds);48 49 /**50 * @see org.openqa.selenium.WebElement.Select#getOptions51 * @return List<WebElement>52 */53 List<WebElement> getOptions();54 55 /**56 * Helper Method : wraps function with Wait57 * @return List<WebElement>58 */59 List<WebElement> getOptionsWhenVisible();60 61 /**62 * Helper Method : wraps function with Wait63 * @param waitTimeInSeconds64 * @return List<WebElement65 */66 List<WebElement> getOptionsWhenVisible(int waitTimeInSeconds);67 68 /**69 * @see org.openqa.selenium.WebElement.Select#getAllSelectedOptions70 * @return List<WebElement>71 */72 List<WebElement> getAllSelectedOptions();73 74 /**75 * Helper Method : wraps function with Wait76 * @return List<WebElement77 */78 List<WebElement> getAllSelectedOptionsWhenVisible();79 80 /**81 * Helper Method : wraps function with Wait82 * @param waitTimeInSeconds83 * @return List<WebElement>84 */85 List<WebElement> getAllSelectedOptionsWhenVisible(int waitTimeInSeconds);86 87 /**88 * @see org.openqa.selenium.WebElement.Select#getFirstSelectedOption89 * @return WebElement90 */91 WebElement getFirstSelectedOption();92 93 /**94 * Helper Method : wraps function with Wait95 * @return WebElement96 */97 WebElement getFirstSelectedOptionWhenVisible();98 99 /**100 * Helper Method : wraps function with Wait101 * @param waitTimeInSeconds102 * @return WebElement103 */104 WebElement getFirstSelectedOptionWhenVisible(int waitTimeInSeconds);105 106 /**107 * @see org.openqa.selenium.WebElement.Select#selectByVisibleText108 * @param text109 * @return T the fluent interface type110 */111 T selectByVisibleText(String text);112 113 /**114 * Helper Method : wraps function with Wait115 * @param text116 * @return T the fluent interface type117 */118 T selectByVisibleTextWhenVisible(String text);119 120 /**121 * Helper Method : wraps function with Wait122 * @param text123 * @param waitTimeInSeconds124 * @return T the fluent interface type125 */126 T selectByVisibleTextWhenVisible(String text, int waitTimeInSeconds);127 128 /**129 * @see org.openqa.selenium.WebElement.Select#selectByIndex130 * @param index131 * @return T the fluent interface type132 */133 T selectByIndex(int index);134 135 /**136 * Helper Method : wraps function with Wait137 * @param index138 * @return T the fluent interface type139 */140 T selectByIndexWhenVisible(int index);141 142 /**143 * Helper Method : wraps function with Wait144 * @param index145 * @param waitTimeInSeconds146 * @return T the fluent interface type147 */148 T selectByIndexWhenVisible(int index, int waitTimeInSeconds);149 150 /**151 * @see org.openqa.selenium.WebElement.Select#selectByValue152 * @param value153 * @return T the fluent interface type154 */155 T selectByValue(String value);156 157 /**158 * Helper Method : wraps function with Wait159 * @param value160 * @return T the fluent interface type161 */162 T selectByValueWhenVisible(String value);163 164 /**165 * Helper Method : wraps function with Wait166 * @param value167 * @param waitTimeInSeconds168 * @return T the fluent interface type169 */170 T selectByValueWhenVisible(String value, int waitTimeInSeconds);171 172 /**173 * @see org.openqa.selenium.WebElement.Select#deselectAll174 * @return T the fluent interface type175 */176 T deselectAll();177 178 /**179 * Helper Method : wraps function with Wait180 * @return T the fluent interface type181 */182 T deselectAllWhenVisible();183 184 /**185 * Helper Method : wraps function with Wait186 * @param waitTimeInSeconds187 * @return T the fluent interface type188 */189 T deselectAllWhenVisible(int waitTimeInSeconds);190 191 /**192 * @see org.openqa.selenium.WebElement.Select#deselectByValue193 * @param value194 * @return T the fluent interface type195 */196 T deselectByValue(String value);197 198 /**199 * Helper Method : wraps function with Wait200 * @param value201 * @return T the fluent interface type202 */203 T deselectByValueWhenVisible(String value);204 205 /**206 * Helper Method : wraps function with Wait207 * @param value208 * @param waitTimeInSeconds209 * @return T the fluent interface type210 */211 T deselectByValueWhenVisible(String value, int waitTimeInSeconds);212 213 /**214 * @see org.openqa.selenium.WebElement.Select#deselectByIndex215 * @param index216 * @return T the fluent interface type217 */218 T deselectByIndex(int index);219 220 /**221 * Helper Method : wraps function with Wait222 * @param index223 * @return T the fluent interface type224 */225 T deselectByIndexWhenVisible(int index);226 227 /**228 * Helper Method : wraps function with Wait229 * @param index230 * @param waitTimeInSeconds231 * @return T the fluent interface type232 */233 T deselectByIndexWhenVisible(int index, int waitTimeInSeconds);234 235 /**236 * @see org.openqa.selenium.WebElement.Select#deselectByVisibleText237 * @param text238 * @return T the fluent interface type239 */240 T deselectByVisibleText(String text);241 242 /**243 * Helper Method : wraps function with Wait244 * @param text245 * @return T the fluent interface type246 */247 T deselectByVisibleTextWhenVisible(String text);248 249 /**250 * Helper Method : wraps function with Wait251 * @param text252 * @param waitTimeInSeconds253 * @return T the fluent interface type254 */255 T deselectByVisibleTextWhenVisible(String text, int waitTimeInSeconds);256}...

Full Screen

Full Screen

Source:CustomWebDriverEventListener.java Github

copy

Full Screen

1/*2 *3 * Copyright (C) 2007-2015 Licensed to the Comunes Association (CA) under4 * one or more contributor license agreements (see COPYRIGHT for details).5 * The CA licenses this file to you under the GNU Affero General Public6 * License version 3, (the "License"); you may not use this file except in7 * compliance with the License. This file is part of kune.8 *9 * This program is free software: you can redistribute it and/or modify10 * it under the terms of the GNU Affero General Public License as11 * published by the Free Software Foundation, either version 3 of the12 * License, or (at your option) any later version.13 *14 * This program is distributed in the hope that it will be useful,15 * but WITHOUT ANY WARRANTY; without even the implied warranty of16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17 * GNU Affero General Public License for more details.18 *19 * You should have received a copy of the GNU Affero General Public License20 * along with this program. If not, see <http://www.gnu.org/licenses/>.21 *22 */23package cc.kune.selenium;24import org.openqa.selenium.By;25import org.openqa.selenium.WebDriver;26import org.openqa.selenium.WebElement;27import org.openqa.selenium.chrome.ChromeDriver;28import org.openqa.selenium.support.events.WebDriverEventListener;29// TODO: Auto-generated Javadoc30/**31 * The listener interface for receiving customWebDriverEvent events. The class32 * that is interested in processing a customWebDriverEvent event implements this33 * interface, and the object created with that class is registered with a34 * component using the component's35 * <code>addCustomWebDriverEventListener<code> method. When36 * the customWebDriverEvent event occurs, that object's appropriate37 * method is invoked.38 * 39 * @see CustomWebDriverEventEvent40 */41public class CustomWebDriverEventListener implements WebDriverEventListener {42 /*43 * (non-Javadoc)44 * 45 * @see46 * org.openqa.selenium.support.events.WebDriverEventListener#afterChangeValueOf47 * (org.openqa.selenium.WebElement, org.openqa.selenium.WebDriver)48 */49 @Override50 public void afterChangeValueOf(final WebElement element, final WebDriver driver) {51 // SeleniumUtils.showCursor(driver);52 sleep(400);53 }54 /*55 * (non-Javadoc)56 * 57 * @see58 * org.openqa.selenium.support.events.WebDriverEventListener#afterClickOn(59 * org.openqa.selenium.WebElement, org.openqa.selenium.WebDriver)60 */61 @Override62 public void afterClickOn(final WebElement element, final WebDriver driver) {63 // SeleniumUtils.showCursor(driver);64 slow();65 }66 /*67 * (non-Javadoc)68 * 69 * @see70 * org.openqa.selenium.support.events.WebDriverEventListener#afterFindBy(org71 * .openqa.selenium.By, org.openqa.selenium.WebElement,72 * org.openqa.selenium.WebDriver)73 */74 @Override75 public void afterFindBy(final By by, final WebElement element, final WebDriver driver) {76 }77 /*78 * (non-Javadoc)79 * 80 * @see81 * org.openqa.selenium.support.events.WebDriverEventListener#afterNavigateBack82 * (org.openqa.selenium.WebDriver)83 */84 @Override85 public void afterNavigateBack(final WebDriver driver) {86 slow();87 }88 /*89 * (non-Javadoc)90 * 91 * @see92 * org.openqa.selenium.support.events.WebDriverEventListener#afterNavigateForward93 * (org.openqa.selenium.WebDriver)94 */95 @Override96 public void afterNavigateForward(final WebDriver driver) {97 slow();98 }99 /*100 * (non-Javadoc)101 * 102 * @see103 * org.openqa.selenium.support.events.WebDriverEventListener#afterNavigateTo104 * (java.lang.String, org.openqa.selenium.WebDriver)105 */106 @Override107 public void afterNavigateTo(final String url, final WebDriver driver) {108 sleep(500);109 }110 /*111 * (non-Javadoc)112 * 113 * @see114 * org.openqa.selenium.support.events.WebDriverEventListener#afterScript(java115 * .lang.String, org.openqa.selenium.WebDriver)116 */117 @Override118 public void afterScript(final String script, final WebDriver driver) {119 }120 /*121 * (non-Javadoc)122 * 123 * @see124 * org.openqa.selenium.support.events.WebDriverEventListener#beforeChangeValueOf125 * (org.openqa.selenium.WebElement, org.openqa.selenium.WebDriver)126 */127 @Override128 public void beforeChangeValueOf(final WebElement element, final WebDriver driver) {129 SeleniumUtils.hightlight(element, driver);130 sleep(150);131 // SeleniumUtils.hideCursor(driver);132 }133 /*134 * (non-Javadoc)135 * 136 * @see137 * org.openqa.selenium.support.events.WebDriverEventListener#beforeClickOn138 * (org.openqa.selenium.WebElement, org.openqa.selenium.WebDriver)139 */140 @Override141 public void beforeClickOn(final WebElement element, final WebDriver driver) {142 SeleniumUtils.hightlight(element, driver);143 slow();144 // SeleniumUtils.hideCursor(driver);145 }146 /*147 * (non-Javadoc)148 * 149 * @see150 * org.openqa.selenium.support.events.WebDriverEventListener#beforeFindBy(151 * org.openqa.selenium.By, org.openqa.selenium.WebElement,152 * org.openqa.selenium.WebDriver)153 */154 @Override155 public void beforeFindBy(final By by, final WebElement element, final WebDriver driver) {156 }157 /*158 * (non-Javadoc)159 * 160 * @see161 * org.openqa.selenium.support.events.WebDriverEventListener#beforeNavigateBack162 * (org.openqa.selenium.WebDriver)163 */164 @Override165 public void beforeNavigateBack(final WebDriver driver) {166 }167 /*168 * (non-Javadoc)169 * 170 * @see171 * org.openqa.selenium.support.events.WebDriverEventListener#beforeNavigateForward172 * (org.openqa.selenium.WebDriver)173 */174 @Override175 public void beforeNavigateForward(final WebDriver driver) {176 }177 /*178 * (non-Javadoc)179 * 180 * @see181 * org.openqa.selenium.support.events.WebDriverEventListener#beforeNavigateTo182 * (java.lang.String, org.openqa.selenium.WebDriver)183 */184 @Override185 public void beforeNavigateTo(final String url, final WebDriver driver) {186 }187 /*188 * (non-Javadoc)189 * 190 * @see191 * org.openqa.selenium.support.events.WebDriverEventListener#beforeScript(192 * java.lang.String, org.openqa.selenium.WebDriver)193 */194 @Override195 public void beforeScript(final String script, final WebDriver driver) {196 }197 /*198 * (non-Javadoc)199 * 200 * @see201 * org.openqa.selenium.support.events.WebDriverEventListener#onException(java202 * .lang.Throwable, org.openqa.selenium.WebDriver)203 */204 @Override205 public void onException(final Throwable throwable, final WebDriver driver) {206 if (driver instanceof ChromeDriver) {207 // ((ChromeDriver) driver).getScreenshotAs(OutputType.FILE);208 }209 }210 /**211 * Sleep.212 * 213 * @param milliseconds214 * the milliseconds215 */216 private void sleep(final int milliseconds) {217 SeleniumUtils.sleep(milliseconds);218 }219 /**220 * Slow.221 */222 private void slow() {223 sleep(700);224 }225}...

Full Screen

Full Screen

Source:EventListener.java Github

copy

Full Screen

1/*2 * 3 */4package com.mifos.testing.framework.webdriver;5import org.apache.commons.io.FileUtils;6import org.openqa.selenium.*;7import org.openqa.selenium.support.events.WebDriverEventListener;8import java.io.File;9import java.io.IOException;10// TODO: Auto-generated Javadoc11/**12 * The listener interface for receiving event events. The class that is13 * interested in processing a event event implements this interface, and the14 * object created with that class is registered with a component using the15 * component's <code>addEventListener<code> method. When16 * the event event occurs, that object's appropriate17 * method is invoked.18 * 19 * @see EventEvent20 */21public class EventListener implements WebDriverEventListener {22 // @Override23 // public void onException(java.lang.Throwable throwable, WebDriver driver)24 // {25 //26 // WebDriver augmentedDriver = new Augmenter().augment(driver);27 // File source =28 // ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);29 //30 // String path = "./target/screenshots/";31 //32 // if (!(System.getProperty("screenshot.folder").equals(null)) ){33 // path = System.getProperty("screenshot.folder");34 // }35 //36 // path = path + source.getName();37 //38 // try {39 // FileUtils.copyFile(source, new File(path));40 // } catch (IOException e) {41 // // TODO Auto-generated catch block42 // e.printStackTrace();43 // }44 //45 // }46 /*47 * (non-Javadoc)48 * 49 * @see50 * org.openqa.selenium.support.events.WebDriverEventListener#afterChangeValueOf51 * (org.openqa.selenium.WebElement, org.openqa.selenium.WebDriver)52 */53 @Override54 public void afterChangeValueOf(WebElement arg0, WebDriver arg1) {55 // TODO Auto-generated method stub56 }57 /*58 * (non-Javadoc)59 * 60 * @see61 * org.openqa.selenium.support.events.WebDriverEventListener#afterClickOn62 * (org.openqa.selenium.WebElement, org.openqa.selenium.WebDriver)63 */64 @Override65 public void afterClickOn(WebElement arg0, WebDriver arg1) {66 // TODO Auto-generated method stub67 }68 /*69 * (non-Javadoc)70 * 71 * @see72 * org.openqa.selenium.support.events.WebDriverEventListener#afterFindBy73 * (org.openqa.selenium.By, org.openqa.selenium.WebElement,74 * org.openqa.selenium.WebDriver)75 */76 @Override77 public void afterFindBy(By arg0, WebElement arg1, WebDriver arg2) {78 arg1.sendKeys(Keys.ARROW_DOWN);79 }80 /*81 * (non-Javadoc)82 * 83 * @see84 * org.openqa.selenium.support.events.WebDriverEventListener#afterNavigateBack85 * (org.openqa.selenium.WebDriver)86 */87 @Override88 public void afterNavigateBack(WebDriver arg0) {89 // TODO Auto-generated method stub90 }91 /*92 * (non-Javadoc)93 * 94 * @see org.openqa.selenium.support.events.WebDriverEventListener#95 * afterNavigateForward(org.openqa.selenium.WebDriver)96 */97 @Override98 public void afterNavigateForward(WebDriver arg0) {99 // TODO Auto-generated method stub100 }101 /*102 * (non-Javadoc)103 * 104 * @see105 * org.openqa.selenium.support.events.WebDriverEventListener#afterNavigateTo106 * (java.lang.String, org.openqa.selenium.WebDriver)107 */108 @Override109 public void afterNavigateTo(String arg0, WebDriver arg1) {110 // TODO Auto-generated method stub111 }112 /*113 * (non-Javadoc)114 * 115 * @see116 * org.openqa.selenium.support.events.WebDriverEventListener#afterScript117 * (java.lang.String, org.openqa.selenium.WebDriver)118 */119 @Override120 public void afterScript(String arg0, WebDriver arg1) {121 // TODO Auto-generated method stub122 }123 /*124 * (non-Javadoc)125 * 126 * @see127 * org.openqa.selenium.support.events.WebDriverEventListener#beforeChangeValueOf128 * (org.openqa.selenium.WebElement, org.openqa.selenium.WebDriver)129 */130 @Override131 public void beforeChangeValueOf(WebElement arg0, WebDriver arg1) {132 // TODO Auto-generated method stub133 }134 /*135 * (non-Javadoc)136 * 137 * @see138 * org.openqa.selenium.support.events.WebDriverEventListener#beforeClickOn139 * (org.openqa.selenium.WebElement, org.openqa.selenium.WebDriver)140 */141 @Override142 public void beforeClickOn(WebElement arg0, WebDriver arg1) {143 // TODO Auto-generated method stub144 }145 /*146 * (non-Javadoc)147 * 148 * @see149 * org.openqa.selenium.support.events.WebDriverEventListener#beforeFindBy150 * (org.openqa.selenium.By, org.openqa.selenium.WebElement,151 * org.openqa.selenium.WebDriver)152 */153 @Override154 public void beforeFindBy(By arg0, WebElement arg1, WebDriver arg2) {155 // TODO Auto-generated method stub156 }157 /*158 * (non-Javadoc)159 * 160 * @see161 * org.openqa.selenium.support.events.WebDriverEventListener#beforeNavigateBack162 * (org.openqa.selenium.WebDriver)163 */164 @Override165 public void beforeNavigateBack(WebDriver arg0) {166 // TODO Auto-generated method stub167 }168 /*169 * (non-Javadoc)170 * 171 * @see org.openqa.selenium.support.events.WebDriverEventListener#172 * beforeNavigateForward(org.openqa.selenium.WebDriver)173 */174 @Override175 public void beforeNavigateForward(WebDriver arg0) {176 // TODO Auto-generated method stub177 }178 /*179 * (non-Javadoc)180 * 181 * @see182 * org.openqa.selenium.support.events.WebDriverEventListener#beforeNavigateTo183 * (java.lang.String, org.openqa.selenium.WebDriver)184 */185 @Override186 public void beforeNavigateTo(String arg0, WebDriver arg1) {187 // TODO Auto-generated method stub188 }189 /*190 * (non-Javadoc)191 * 192 * @see193 * org.openqa.selenium.support.events.WebDriverEventListener#beforeScript194 * (java.lang.String, org.openqa.selenium.WebDriver)195 */196 @Override197 public void beforeScript(String arg0, WebDriver arg1) {198 // TODO Auto-generated method stub199 }200 /*201 * (non-Javadoc)202 * 203 * @see204 * org.openqa.selenium.support.events.WebDriverEventListener#onException205 * (java.lang.Throwable, org.openqa.selenium.WebDriver)206 */207 @Override208 public void onException(Throwable e, WebDriver driver) {209 File source = ((TakesScreenshot) driver)210 .getScreenshotAs(OutputType.FILE);211 String path = "./target/screenshots/";212 // if (!(System.getProperty("screenshot.folder").equals(null)) ){213 // path = System.getProperty("screenshot.folder");214 // }215 path = path + source.getName();216 try {217 FileUtils.copyFile(source, new File(path));218 } catch (IOException e2) {219 // TODO Auto-generated catch block220 e.printStackTrace();221 }222 System.setProperty("screenshottaken", "true");223 }224}...

Full Screen

Full Screen

Source:AmazonHomePage.java Github

copy

Full Screen

1package examples;23import java.util.List;4import java.util.concurrent.TimeUnit;56import org.openqa.selenium.By;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.WebElement;9import org.openqa.selenium.chrome.ChromeDriver;10import org.openqa.selenium.interactions.Actions;11import org.openqa.selenium.support.ui.ExpectedConditions;12import org.openqa.selenium.support.ui.FluentWait;13import org.openqa.selenium.support.ui.WebDriverWait;14import org.testng.annotations.Test;1516import com.google.common.base.Function;1718public class AmazonHomePage {19 20 WebDriver driver;21 22 @Test 23 public void signInTest(){24 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Bhushan\\myjava\\chromedriver.exe");25 driver = new ChromeDriver();26 driver.get("https://www.amazon.com/");27 System.out.println("home page Title:"+ driver.getTitle());28 driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);29 30 WebElement element = driver.findElement(By.cssSelector("#nav-link-accountList>span:nth-of-type(2)")); // listen to 2017/06/22 class 23 mints video31 element.click();32 System.out.println("sign in page title :" + driver.getTitle());33 34 }35 36 public void tryPrimeTest(){37 38 driver.get("https://www.amazon.com/");39 System.out.println("home page Title:"+ driver.getTitle());40 WebElement element = driver.findElement(By.cssSelector("#nav-link-prime .nav-line-2"));41 42 Actions action = new Actions(driver); //abject will take driver input43 action.moveToElement(element).perform(); // moveToElement will take the mouse control to a particular element//perform perform action44 45 WebDriverWait wait = new WebDriverWait(driver,30);46 element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".prime-button-try>a")));47 element.click();48 System.out.println("home page Title:"+ driver.getTitle());49 //driver.findElement(By.cssSelector(".prime-button-try>a")).click();50 }51 52 public void searchBoxTest() throws InterruptedException{53 driver.get("https://www.amazon.com/");54 WebElement element = driver.findElement(By.id("twotabsearchtextbox"));55 element.click();56 element.sendKeys("w");57 element.sendKeys("a");58 59 Thread.sleep(1000);60 element.sendKeys("t");61 62 //List<WebElement>elements = driver.findElements(By.cssSelector("#suggestions div"));63 64 65 FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver);66 wait.pollingEvery(5,TimeUnit.SECONDS);67 wait.withTimeout(30,TimeUnit.SECONDS);68 69 //List<WebElement>elements =wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("#suggestions div")));70 //System.out.println("list size:" + elements.size());71 72 WebElement elm = wait.until(function);73 System.out.println("element selected:"+ elm.getText());74 }75 7677 78 Function<WebDriver,WebElement> function = new Function<WebDriver,WebElement>(){ // this function is an Interface...whereWebDrive is Input & WebElement is output79 80 public WebElement apply(WebDriver arg0){ // apply -- is a method81 List<WebElement>elements = wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("#suggestions div")));82 83 System.out.println("list size:"+ elements.size());84 WebElement elm1 = null;85 for(WebElement elm: elements){86 elm1 = elm;87 System.out.println(elm.getText());88 }89 return elm1;90 }91 };9293} ...

Full Screen

Full Screen

Source:SearchingEventListener.java Github

copy

Full Screen

1/*2 * Licensed under the Apache License, Version 2.0 (the "License");3 * you may not use this file except in compliance with the License.4 * See the NOTICE file distributed with this work for additional5 * information regarding copyright ownership.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.mengge.events.api.general;17import com.mengge.events.api.Listener;18import org.openqa.selenium.By;19import org.openqa.selenium.WebDriver;20import org.openqa.selenium.WebElement;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:ElementEventListener.java Github

copy

Full Screen

1/*2 * Licensed under the Apache License, Version 2.0 (the "License");3 * you may not use this file except in compliance with the License.4 * See the NOTICE file distributed with this work for additional5 * information regarding copyright ownership.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.mengge.events.api.general;17import com.mengge.events.api.Listener;18import org.openqa.selenium.WebDriver;19import org.openqa.selenium.WebElement;20public interface ElementEventListener extends Listener {21 /**22 * Called before {@link org.openqa.selenium.WebElement#click WebElement.click()}.23 *24 * @param driver WebDriver25 * @param element the WebElement being used for the action26 */27 void beforeClickOn(WebElement element, WebDriver driver);28 /**29 * Called after {@link org.openqa.selenium.WebElement#click WebElement.click()}.30 * Not called, if an exception is thrown.31 *32 * @param driver WebDriver33 * @param element the WebElement being used for the action34 */35 void afterClickOn(WebElement element, WebDriver driver);36 /**37 * Called before {@link org.openqa.selenium.WebElement#clear WebElement.clear()},38 * {@link org.openqa.selenium.WebElement#sendKeys WebElement.sendKeys(...)}.39 *40 * @param driver WebDriver41 * @param element the WebElement being used for the action42 */43 void beforeChangeValueOf(WebElement element, WebDriver driver);44 /**45 * Called after {@link org.openqa.selenium.WebElement#clear WebElement.clear()},46 * {@link org.openqa.selenium.WebElement#sendKeys WebElement.sendKeys(...)} .47 * Not called, if an exception is thrown.48 *49 * @param driver WebDriver50 * @param element the WebElement being used for the action51 */52 void afterChangeValueOf(WebElement element, WebDriver driver);53}...

Full Screen

Full Screen

Source:Listbox.java Github

copy

Full Screen

1package com.orasi.core.interfaces;2import java.util.List;3import org.openqa.selenium.WebElement;4import com.orasi.core.interfaces.impl.ListboxImpl;5import com.orasi.core.interfaces.impl.internal.ImplementedBy;6/**7 * Interface for a select element.8 */9@ImplementedBy(ListboxImpl.class)10public interface Listbox extends Element {11 /**12 * @summary - Wraps Selenium's method.13 * @param value14 * - the value/option to select.15 * @see org.openqa.selenium.support.ui.Select#selectByVisibleText(String)16 */17 void select(String value);18 /**19 * @summary - Wraps Selenium's method.20 * @param value21 * - the value/option to select.22 * @see org.openqa.selenium.support.ui.Select#selectByValue(String)23 */24 void selectValue(String value);25 /**26 * @summary - Wraps Selenium's method.27 * @see org.openqa.selenium.support.ui.Select#deselectAll()28 */29 void deselectAll();30 /**31 * @summary - Wraps Selenium's method.32 * @param text33 * - text to deselect by visible text34 * @see org.openqa.selenium.support.ui.Select#deselectByVisibleText(String)35 */36 void deselectByVisibleText(String text);37 /**38 * @author Justin39 * @return WebElement40 * @see org.openqa.selenium.support.ui.Select#getFirstSelectedOption()41 */42 WebElement getFirstSelectedOption();43 /**44 * @author Justin45 * @return WebElement list of all options in a given listbox46 * @see org.openqa.selenium.WebElement#isSelected()47 */48 List<WebElement> getOptions();49 /**50 * @author Justin51 * @return WebElement list of all selected options in a given listbox52 * @see org.openqa.selenium.WebElement#isSelected()53 */54 List<WebElement> getAllSelectedOptions();55 /**56 * @author Justin57 * @return {@link boolean} TRUE if element is currently select58 * @see org.openqa.selenium.WebElement#isSelected()59 */60 boolean isSelected(String option);61 boolean isMultiple();62}...

Full Screen

Full Screen

Interface WebElement

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebElement;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.By;4import org.openqa.selenium.Keys;5import org.openqa.selenium.support.ui.WebDriverWait;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.chrome.ChromeDriver;8import org.openqa.selenium.chrome.ChromeOptions;9import org.openqa.selenium.remote.DesiredCapabilities;10import com.relevantcodes.extentreports.ExtentReports;11import com.relevantcodes.extentreports.ExtentTest;12import com.relevantcodes.extentreports.ExtentHtmlReporter;13import com.aventstack.extentreports.ExtentSparkReporter;14import com.aventstack.extentreports.ExtentReports;15import com.aventstack.extentreports.ExtentTest;16import java.io.File;17import java.io.IOException;18import java.io.FileInputStream;19import java.io.FileOutputStream;20import java.io.BufferedInputStream;21import java.io.BufferedOutputStream;22import java.util.zip.ZipEntry;

Full Screen

Full Screen

Interface WebElement

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebElement;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;5public class WebElementDemo {6 public static void main(String[] args) {7 WebDriver driver = new ChromeDriver();8 driver.manage().window().maximize();9 WebElement searchBox = driver.findElement(By.name("q"));10 searchBox.sendKeys("Selenium");11 driver.close();12 }13}14import org.openqa.selenium.WebElement;15import org.openqa.selenium.By;16import org.openqa.selenium.WebDriver;17import org.openqa.selenium.chrome.ChromeDriver;18public class WebElementDemo {19 public static void main(String[] args) {20 WebDriver driver = new ChromeDriver();21 driver.manage().window().maximize();22 WebElement searchBox = driver.findElement(By.name("q"));23 searchBox.sendKeys("Selenium");24 driver.close();25 }26}

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.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful