How to use By class of org.openqa.selenium package

Best Selenium code snippet using org.openqa.selenium.By

Source:OrasiDriver.java Github

copy

Full Screen

2import java.net.URL;3import java.util.List;4import java.util.Set;5import java.util.concurrent.TimeUnit;6import org.openqa.selenium.By;7import org.openqa.selenium.JavascriptExecutor;8import org.openqa.selenium.OutputType;9import org.openqa.selenium.Platform;10import org.openqa.selenium.TakesScreenshot;11import org.openqa.selenium.WebDriver;12import org.openqa.selenium.WebDriverException;13import org.openqa.selenium.WebElement;14import org.openqa.selenium.chrome.ChromeDriver;15import org.openqa.selenium.edge.EdgeDriver;16import org.openqa.selenium.firefox.FirefoxDriver;17import org.openqa.selenium.htmlunit.HtmlUnitDriver;18import org.openqa.selenium.ie.InternetExplorerDriver;19import org.openqa.selenium.remote.DesiredCapabilities;20import org.openqa.selenium.remote.RemoteExecuteMethod;21import org.openqa.selenium.remote.RemoteKeyboard;22import org.openqa.selenium.remote.RemoteWebDriver;23import org.openqa.selenium.safari.SafariDriver;24import com.gargoylesoftware.htmlunit.WebWindow;25import com.gargoylesoftware.htmlunit.javascript.background.DefaultJavaScriptExecutor;26import com.gargoylesoftware.htmlunit.javascript.background.JavaScriptExecutor;27import com.orasi.core.by.angular.ByNG;28import com.orasi.core.by.angular.ByNG.ByNGButton;29import com.orasi.core.by.angular.ByNG.ByNGController;30import com.orasi.core.by.angular.ByNG.ByNGModel;31import com.orasi.core.by.angular.ByNG.ByNGRepeater;32import com.orasi.core.by.angular.ByNG.ByNGShow;33import com.orasi.core.by.angular.internal.ByAngular;34import com.orasi.core.interfaces.Button;35import com.orasi.core.interfaces.Checkbox;36import com.orasi.core.interfaces.Element;37import com.orasi.core.interfaces.Label;38import com.orasi.core.interfaces.Link;39import com.orasi.core.interfaces.Listbox;40import com.orasi.core.interfaces.RadioGroup;41import com.orasi.core.interfaces.Textbox;42import com.orasi.core.interfaces.Webtable;43import com.orasi.core.interfaces.impl.ButtonImpl;44import com.orasi.core.interfaces.impl.CheckboxImpl;45import com.orasi.core.interfaces.impl.ElementImpl;46import com.orasi.core.interfaces.impl.LabelImpl;47import com.orasi.core.interfaces.impl.LinkImpl;48import com.orasi.core.interfaces.impl.ListboxImpl;49import com.orasi.core.interfaces.impl.RadioGroupImpl;50import com.orasi.core.interfaces.impl.TextboxImpl;51import com.orasi.core.interfaces.impl.WebtableImpl;52import com.orasi.utils.dataHelpers.DataWarehouse;53import com.orasi.utils.debugging.Colors;54import com.orasi.utils.debugging.Highlight;55public class OrasiDriver implements WebDriver, JavaScriptExecutor, TakesScreenshot {56 /*57 * Define fields to be used by an OrasiDriver58 */59 private static final long serialVersionUID = -657563735440878909L;60 private WebDriver driver;61 private DataWarehouse dataWarehouse;62 private int currentPageTimeout = Constants.PAGE_TIMEOUT;63 private int currentElementTimeout = Constants.ELEMENT_TIMEOUT;64 private int currentScriptTimeout = Constants.DEFAULT_GLOBAL_DRIVER_TIMEOUT;65 public OrasiDriver() {}66 /**67 * Constructor for OrasiDriver68 * Example usage: OrasiDriver oDriver = new OrasiDriver(caps);69 * @param caps - Selenium desired capabilities, used to configure the OrasiDriver70 */71 public OrasiDriver(DesiredCapabilities caps) {72 setDriverWithCapabilties(caps);73 }74 /**75 * Constructor for OrasiDriver, specifically used to generate a remote WebDriver76 * Example usage: OrasiDriver oDriver = new OrasiDriver(caps, url);77 * @param caps - Selenium desired capabilities, used to configure the OrasiDriver78 * @param url - 79 */80 public OrasiDriver(DesiredCapabilities caps, URL url) {81 driver = new RemoteWebDriver(url, caps);82 }83 /**84 * Method to return the current OrasiDriver85 * Example usage: getDriver().getDriver();86 * @return - current OrasiDriver87 */88 public WebDriver getWebDriver() {89 return driver;90 }91 public void setDriver(WebDriver driver) {92 this.driver = driver;93 }94 /**95 * Method to navigate to a user-defined URL96 * Example usage: getDriver().get(url);97 * @param url - URL to which to navigate98 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#get-java.lang.String-99 */100 @Override101 public void get(String url) {102 driver.get(url);103 }104 /**105 * Method to return the current URL106 * Example usage: getDriver().getCurrentUrl();107 * @return - current URL108 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#getCurrentUrl--109 */110 @Override111 public String getCurrentUrl() {112 return driver.getCurrentUrl();113 }114 /**115 * Method to return the title of the current page116 * Example usage: getDriver().getTitle();117 * @return - title of the current page118 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#getTitle--119 */120 @Override121 public String getTitle() {122 return driver.getTitle();123 }124 /**125 * Method to set the script timeout126 * @param timeout - timeout with which to set the script timeout127 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html#setScriptTimeout-long-java.util.concurrent.TimeUnit-128 */129 public void setScriptTimeout(int timeout) {130 setScriptTimeout(timeout, TimeUnit.SECONDS);131 }132 /**133 * Method to set the script timeout134 * @param timeout - timeout with which to set the script timeout135 * @param timeUnit -Java TimeUnit, used to determine the unit of time to be associated with the timeout136 * @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/TimeUnit.html137 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html#setScriptTimeout-long-java.util.concurrent.TimeUnit-138 */139 public void setScriptTimeout(int timeout, TimeUnit timeUnit) {140 this.currentScriptTimeout = timeout;141 driver.manage().timeouts().setScriptTimeout(timeout, timeUnit);142 }143 /**144 * Method to return the script timeout145 * @return - script timeout146 */147 public int getScriptTimeout() {148 return currentScriptTimeout;149 }150 /**151 * Method to set the page timeout152 * @param timeout - timeout with which to set the page timeout153 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html#pageLoadTimeout-long-java.util.concurrent.TimeUnit-154 */155 public void setPageTimeout(int timeout) {156 setPageTimeout(timeout, TimeUnit.SECONDS);157 }158 /**159 * Method to set the page timeout160 * @param timeout - timeout with which to set the page timeout161 * @param timeUnit -Java TimeUnit, used to determine the unit of time to be associated with the timeout162 * @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/TimeUnit.html163 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html#pageLoadTimeout-long-java.util.concurrent.TimeUnit-164 */165 public void setPageTimeout(int timeout, TimeUnit timeUnit) {166 if (driver instanceof SafariDriver || driver.toString().contains("safari")) {167 System.out.println("SafariDriver does not support pageLoadTimeout");168 } else {169 this.currentPageTimeout = timeout;170 driver.manage().timeouts().pageLoadTimeout(timeout, timeUnit);171 }172 }173 /**174 * Method to return the page timeout175 * @return - page timeout176 */177 public int getPageTimeout() {178 return currentPageTimeout;179 }180 /**181 * Method to set element timeout182 * @param timeout - timeout with which to set the element timeout183 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html#implicitlyWait-long-java.util.concurrent.TimeUnit-184 */185 public void setElementTimeout(int timeout) {186 setElementTimeout(timeout, TimeUnit.SECONDS);187 }188 /**189 * Method to set the element timeout190 * @param timeout - timeout with which to set the element timeout191 * @param timeUnit192 * @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/TimeUnit.html193 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.Timeouts.html#implicitlyWait-long-java.util.concurrent.TimeUnit-194 */195 public void setElementTimeout(int timeout, TimeUnit timeUnit) {196 this.currentElementTimeout = timeout;197 driver.manage().timeouts().implicitlyWait(timeout, timeUnit);198 }199 /**200 * Method to return the element timeout201 * @return - element timeout202 */203 public int getElementTimeout() {204 return currentElementTimeout;205 }206 /*207 * public List<Element> findElements(By by) { List<WebElement> webElements =208 * driver.findElements(by); List test = webElements; List<Element> elements=209 * (List<Element>)test; return elements; }210 */211 /**212 * Method to find all WebElements for a given page, using a Selenium <b><i>By</i></b> locator213 * @param by - Selenium <b><i>By</i></b> locator with which to locate WebElements214 * @return - List of WebElements, if any, found by using the Selenium <b><i>By</i></b> locator215 * @see http://docs.oracle.com/javase/8/docs/api/java/util/List.html216 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/By.html217 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElements-org.openqa.selenium.By-218 */219 @Override220 public List<WebElement> findElements(By by) {221 return findWebElements(by);222 }223 /**224 * Method to find all WebElements for a given page, using a Selenium <b><i>By</i></b> locator225 * @param by - Selenium <b><i>By</i></b> locator with which to locate WebElements226 * @return - List of WebElements, if any, found by using the Selenium <b><i>By</i></b> locator227 * @see http://docs.oracle.com/javase/8/docs/api/java/util/List.html228 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/By.html229 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElements-org.openqa.selenium.By-230 */231 public List<WebElement> findWebElements(By by) {232 return driver.findElements(by);233 }234 /**235 * Method to find a single Element for a given page, using a Selenium <b><i>By</i></b> locator236 * @param by - Selenium <b><i>By</i></b> locator with which to locate the Element237 * @return Element, if any, found by using the Selenium <b><i>By</i></b> locator 238 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/By.html239 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-240 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/ElementImpl.java241 */242 @Override243 public Element findElement(By by) {244 return new ElementImpl(this, by);245 }246 /**247 * Method to find a single Element for a given page, using an Orasi <b><i>ByNG</i></b> locator248 * @param by - Orasi <b><i>ByNG</i></b> locator with which to locate the Element249 * @return Element, if any, found by using the Orasi <b><i>ByNG</i></b> locator250 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-251 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/ElementImpl.java252 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/by/angular/ByNG.java253 */254 public Element findElement(ByNG by) {255 return new ElementImpl(this, getByNGType(by));256 }257 /**258 * Method to find a single Textbox for a given page, using a Selenium <b><i>By</i></b> locator259 * @param by - Selenium <b><i>By</i></b> locator with which to locate the Textbox260 * @return Textbox, if any, found by using the Selenium <b><i>By</i></b> locator261 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/By.html262 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-263 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/TextboxImpl.java264 */265 public Textbox findTextbox(By by) {266 return new TextboxImpl(this, by);267 }268 /**269 * Method to find a single Textbox for a given page, using an Orasi <b><i>ByNG</i></b> locator270 * @param by - Orasi <b><i>ByNG</i></b> locator with which to locate the Textbox271 * @return Textbox, if any, found by using the Orasi <b><i>ByNG</i></b> locator272 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-273 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/TextboxImpl.java274 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/by/angular/ByNG.java275 */276 public Textbox findTextbox(ByNG by) {277 return new TextboxImpl(this, getByNGType(by));278 }279 /**280 * Method to find a single Button for a given page, using a Selenium <b><i>By</i></b> locator281 * @param by - Selenium <b><i>By</i></b> locator with which to locate the Button282 * @return Button, if any, found by using the Selenium <b><i>By</i></b> locator283 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/By.html284 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-285 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/ButtonImpl.java286 */287 public Button findButton(By by) {288 return new ButtonImpl(this, by);289 }290 /**291 * Method to find a single Button for a given page, using an Orasi <b><i>ByNG</i></b> locator292 * @param by - Orasi <b><i>ByNG</i></b> locator with which to locate the Button293 * @return Button, if any, found by using the Orasi <b><i>ByNG</i></b> locator294 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-295 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/ButtonImpl.java296 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/by/angular/ByNG.java297 */298 public Button findButton(ByNG by) {299 return new ButtonImpl(this, getByNGType(by));300 }301 /**302 * Method to find a single Checkbox for a given page, using a Selenium <b><i>By</i></b> locator303 * @param by - Selenium <b><i>By</i></b> locator with which to locate the Checkbox304 * @return Checkbox, if any, found by using the Selenium <b><i>By</i></b> locator305 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/By.html306 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-307 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/CheckboxImpl.java308 */309 public Checkbox findCheckbox(By by) {310 return new CheckboxImpl(this, by);311 }312 /**313 * Method to find a single Checkbox for a given page, using an Orasi <b><i>ByNG</i></b> locator314 * @param by - Orasi <b><i>ByNG</i></b> locator with which to locate the Checkbox315 * @return Checkbox, if any, found by using the Orasi <b><i>ByNG</i></b> locator316 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-317 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/CheckboxImpl.java318 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/by/angular/ByNG.java319 */320 public Checkbox findCheckbox(ByNG by) {321 return new CheckboxImpl(this, getByNGType(by));322 }323 /**324 * Method to find a single Label for a given page, using a Selenium <b><i>By</i></b> locator325 * @param by - Selenium <b><i>By</i></b> locator with which to locate the Checkbox326 * @return Label, if any, found by using the Selenium <b><i>By</i></b> locator327 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/By.html328 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-329 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/LabelImpl.java330 */331 public Label findLabel(By by) {332 return new LabelImpl(this, by);333 }334 /**335 * Method to find a single Label for a given page, using an Orasi <b><i>ByNG</i></b> locator336 * @param by - Orasi <b><i>ByNG</i></b> locator with which to locate the Label337 * @return Label, if any, found by using the Orasi <b><i>ByNG</i></b> locator338 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-339 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/LabelImpl.java340 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/by/angular/ByNG.java341 */342 public Label findLabel(ByNG by) {343 return new LabelImpl(this, getByNGType(by));344 }345 /**346 * Method to find a single Link for a given page, using a Selenium <b><i>By</i></b> locator347 * @param by - Selenium <b><i>By</i></b> locator with which to locate the Link348 * @return Link, if any, found by using the Selenium <b><i>By</i></b> locator349 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/By.html350 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-351 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/LinkImpl.java352 */353 public Link findLink(By by) {354 return new LinkImpl(this, by);355 }356 /**357 * Method to find a single Link for a given page, using an Orasi <b><i>ByNG</i></b> locator358 * @param by - Orasi <b><i>ByNG</i></b> locator with which to locate the Link359 * @return Link, if any, found by using the Orasi <b><i>ByNG</i></b> locator360 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-361 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/LinkImpl.java362 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/by/angular/ByNG.java363 */364 public Link findLink(ByNG by) {365 return new LinkImpl(this, getByNGType(by));366 }367 /**368 * Method to find a single Listbox for a given page, using a Selenium <b><i>By</i></b> locator369 * @param by - Selenium <b><i>By</i></b> locator with which to locate the Listbox370 * @return Listbox, if any, found by using the Selenium <b><i>By</i></b> locator371 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/By.html372 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-373 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/ListboxImpl.java374 */375 public Listbox findListbox(By by) {376 return new ListboxImpl(this, by);377 }378 /**379 * Method to find a single Listbox for a given page, using an Orasi <b><i>ByNG</i></b> locator380 * @param by - Orasi <b><i>ByNG</i></b> locator with which to locate the Listbox381 * @return Listbox, if any, found by using the Orasi <b><i>ByNG</i></b> locator382 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-383 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/ListboxImpl.java384 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/by/angular/ByNG.java385 */386 public Listbox findListbox(ByNG by) {387 return new ListboxImpl(this, getByNGType(by));388 }389 /**390 * Method to find a single RadioGroup for a given page, using a Selenium <b><i>By</i></b> locator391 * @param by - Selenium <b><i>By</i></b> locator with which to locate the RadioGroup392 * @return RadioGroup, if any, found by using the Selenium <b><i>By</i></b> locator393 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/By.html394 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-395 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/RadioGroupImpl.java396 */397 public RadioGroup findRadioGroup(By by) {398 return new RadioGroupImpl(this, by);399 }400 /**401 * Method to find a single RadioGroup for a given page, using an Orasi <b><i>ByNG</i></b> locator402 * @param by - Orasi <b><i>ByNG</i></b> locator with which to locate the RadioGroup403 * @return RadioGroup, if any, found by using the Orasi <b><i>ByNG</i></b> locator404 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-405 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/RadioGroupImpl.java406 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/by/angular/ByNG.java407 */408 public RadioGroup findRadioGroup(ByNG by) {409 return new RadioGroupImpl(this, getByNGType(by));410 }411 /**412 * Method to find a single Webtable for a given page, using a Selenium <b><i>By</i></b> locator413 * @param by - Selenium <b><i>By</i></b> locator with which to locate the Webtable414 * @return Webtable, if any, found by using the Selenium <b><i>By</i></b> locator415 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/By.html416 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-417 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/WebtableImpl.java418 */419 public Webtable findWebtable(By by) {420 return new WebtableImpl(this, by);421 }422 /**423 * Method to find a single Webtable for a given page, using an Orasi <b><i>ByNG</i></b> locator424 * @param by - Orasi <b><i>ByNG</i></b> locator with which to locate the Webtable425 * @return Webtable, if any, found by using the Orasi <b><i>ByNG</i></b> locator426 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-427 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/interfaces/impl/WebtableImpl.java428 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/by/angular/ByNG.java429 */430 public Webtable findWebtable(ByNG by) {431 return new WebtableImpl(this, getByNGType(by));432 }433 /**434 * Method to find a single WebElement for a given page, using a Selenium <b><i>By</i></b> locator435 * @param by - Selenium <b><i>By</i></b> locator with which to locate the WebElement436 * @return WebElement, if any, found by using the Orasi <b><i>ByNG</i></b> locator437 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By-438 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/By.html439 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html440 */441 public WebElement findWebElement(By by) {442 return driver.findElement(by);443 }444 /**445 * Method to find a single WebElement for a given page, using an Orasi <b><i>ByNG</i></b> locator446 * @param by - Orasi <b><i>ByNG</i></b> locator with which to locate the WebElement447 * @return WebElement, if any, found by using the Orasi <b><i>ByNG</i></b> locator448 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement-org.openqa.selenium.By449 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/by/angular/ByNG.java450 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html451 */452 public WebElement findWebElement(ByNG by) {453 return driver.findElement(getByNGType(by));454 }455 /**456 * Method to return the page source of a given current page457 * @return page source of the given current page458 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#getPageSource--459 */460 @Override461 public String getPageSource() {462 return driver.getPageSource();463 }464 465 /**466 * Method to close the current window467 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#close--468 */469 @Override470 public void close() {471 driver.close();472 }473 /**474 * Method to quit the driver, closing every associated window475 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#quit--476 */477 @Override478 public void quit() {479 driver.quit();480 }481 /**482 * Method to return all window handles contained within a given current driver483 * @return Set of string window handles484 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#getWindowHandles--485 */486 @Override487 public Set<String> getWindowHandles() {488 return driver.getWindowHandles();489 }490 /**491 * Method to return the current window handle for a given currnet driver492 * @return Current window handle as a String493 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#getWindowHandle--494 */495 @Override496 public String getWindowHandle() {497 return driver.getWindowHandle();498 }499 /**500 * Method to switch to another frame or window501 * @return TargetLocator that can be used to select a frame or window502 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#switchTo--503 */504 @Override505 public TargetLocator switchTo() {506 return driver.switchTo();507 }508 /**509 * Method to navigate to a pre-defined URL510 * @return Navigation object that allows the selection of what to do next511 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#navigate--512 */513 @Override514 public Navigation navigate() {515 return driver.navigate();516 }517 /**518 * Method to facilitate the management of the driver (e.g. timeouts, cookies, etc)519 * @return Options interface520 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#manage--521 */522 @Override523 public Options manage() {524 return driver.manage();525 }526 /**527 * Method to clone this class528 * @return Object clone of the current state of this class529 * @throws CloneNotSupportedException530 * @see http://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone()531 */532 @Override533 protected Object clone() throws CloneNotSupportedException {534 return super.clone();535 }536 /**537 * Method to determine if an object is equal to an instance of this class538 * @param obj - object with which to compare539 * @return -boolean true if the two objects are equal, false otherwise540 * @see http://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals(java.lang.Object)541 */542 @Override543 public boolean equals(Object obj) {544 return super.equals(obj);545 }546 /**547 * Method to dispose of system resources548 * @throws Throwable549 * @see http://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize()550 */551 @Override552 protected void finalize() throws Throwable {553 super.finalize();554 }555 /**556 * Method to return the hascode for an instance of this class557 * @return hashcode for an instance of this class as an integer558 * @see http://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--559 */560 @Override561 public int hashCode() {562 return super.hashCode();563 }564 /**565 * Method to return a current instance of this class as a String566 * @return - current instance of this class as a String567 * @see http://docs.oracle.com/javase/8/docs/api/java/lang/String.html#toString--568 */569 @Override570 public String toString() {571 return super.toString();572 }573 /**574 * Method to execute a user-defined JavaScript575 * @param script script to be executed576 * @param parameters any parameters that may need to be referenced by the script577 * @return Return value types vary based on the return type of the script578 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/JavascriptExecutor.html579 */580 public Object executeJavaScript(String script, Object... parameters) {581 return ((JavascriptExecutor) driver).executeScript(script, parameters);582 }583 /**584 * Method to execute a user-defined JavaScript585 * @param script script to be executed586 * @param parameters any parameters that may need to be referenced by the script587 * @return Return value types vary based on the return type of the script588 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/JavascriptExecutor.html589 */590 public Object executeAsyncJavaScript(String script, Object... parameters) {591 return ((JavascriptExecutor) driver).executeAsyncScript(script, parameters);592 }593 @Override594 public void run() {595 ((DefaultJavaScriptExecutor) driver).run();596 }597 @Override598 public void addWindow(WebWindow newWindow) {599 ((DefaultJavaScriptExecutor) driver).addWindow(newWindow);600 }601 @Override602 public void shutdown() {603 ((DefaultJavaScriptExecutor) driver).shutdown();604 }605 @Override606 public int pumpEventLoop(long timeoutMillis) {607 return ((DefaultJavaScriptExecutor) driver).pumpEventLoop(timeoutMillis);608 }609 /**610 * Method to return the RemoteWebDriver session ID611 * @return RemotWebDriver session ID as a String612 * @see https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/remote/SessionId.java613 */614 public String getSessionId() {615 return getRemoteWebDriver().getSessionId().toString();616 }617 /**618 * Method to return the RemoteWebDriver 619 * @return RemotWebDriver 620 * @see https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/remote/RemoteKeyboard.java621 */622 public RemoteKeyboard getKeyboard(){623 return new RemoteKeyboard(new RemoteExecuteMethod(getRemoteWebDriver()));624 }625 626 /**627 * Method to set the capabilities for a driver, based on the browser type628 * @param caps - Selenium DesiredCapabilities to be used to generate a WebDriver629 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/firefox/FirefoxDriver.html630 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/ie/InternetExplorerDriver.html631 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/chrome/ChromeDriver.html632 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/safari/SafariDriver.html633 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/htmlunit/HtmlUnitDriver.html634 * @see http://msdn.microsoft.com/en-us/library/mt188085(v=vs.85).aspx635 */636 private void setDriverWithCapabilties(DesiredCapabilities caps) {637 switch (caps.getBrowserName().toLowerCase()) {638 case "firefox":639 driver = new FirefoxDriver(caps); 640 break;641 case "internet explorer":642 case "iexplore":643 case "ie":644 driver = new InternetExplorerDriver(caps);645 //driver = new SynchronizedInternetExplorerDriver(caps); 646 break;647 case "chrome":648 driver = new ChromeDriver(caps);649 break;650 case "safari":651 driver = new SafariDriver(caps);652 break;653 case "htmlunit":654 case "html":655 driver = new HtmlUnitDriver(true);656 break;657 case "edge":658 case "microsoftedge":659 driver = new EdgeDriver(caps);660 break;661 default:662 break;663 }664 }665 /**666 * Method to return the Selenium DesiredCapabilities667 * @return Selenium DesiredCapabilitie668 */669 public Capabilities getDriverCapability() {670 return new Capabilities();671 }672 /**673 * Method to take a screen shot674 * @param target - image type to capture the screenshot675 * @return Object which si stored information about the screenshot676 * @see http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/TakesScreenshot.html#getScreenshotAs-org.openqa.selenium.OutputType-677 */678 @Override679 public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {680 return ((TakesScreenshot) driver).getScreenshotAs(target);681 }682 /**683 * Subclass to assist with interacting with a RemoteWebDriver684 * @author Justin Phlegar685 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/remote/RemoteWebDriver.html#getCapabilities()686 * @see http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/Capabilities.html687 */688 public class Capabilities {689 public String browserName() {690 if(driver instanceof HtmlUnitDriver) return ((HtmlUnitDriver) driver).getCapabilities().getBrowserName();691 return getRemoteWebDriver().getCapabilities().getBrowserName();692 }693 public String browserVersion() {694 if(driver instanceof HtmlUnitDriver) return ((HtmlUnitDriver) driver).getCapabilities().getVersion();695 return getRemoteWebDriver().getCapabilities().getVersion();696 }697 public String platformOS() {698 if(driver instanceof HtmlUnitDriver) {699 return ((HtmlUnitDriver) driver).getCapabilities().getPlatform().name() + " "700 + ((HtmlUnitDriver) driver).getCapabilities().getPlatform().getMajorVersion() + "."701 + ((HtmlUnitDriver) driver).getCapabilities().getPlatform().getMinorVersion();702 }703 return getRemoteWebDriver().getCapabilities().getPlatform().name() + " "704 + getRemoteWebDriver().getCapabilities().getPlatform().getMajorVersion() + "."705 + getRemoteWebDriver().getCapabilities().getPlatform().getMinorVersion();706 }707 public Platform platform() {708 if(driver instanceof HtmlUnitDriver) return ((HtmlUnitDriver) driver).getCapabilities().getPlatform();709 710 return getRemoteWebDriver().getCapabilities().getPlatform() ;711 }712 }713 /**714 * Method to return an Orasi <b><i>ByAngular.BaseBy</i></b> locator for a given Orasi <b><i>ByNG</i></b> locator715 * @param by - Orasi <b><i>ByNG</i></b> locator716 * @return Orasi <b><i>ByAngular.BaseBy</i></b> locator717 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/by/angular/ByNG.java718 * @see http://github.com/Orasi/Selenium-Java-Core/blob/master/src/main/java/com/orasi/core/by/angular/internal/ByAngular.java719 */720 @SuppressWarnings("static-access")721 private ByAngular.BaseBy getByNGType(ByNG by) {722 String text = by.toString().replace("By.buttonText:", "").trim();723 if (by instanceof ByNGButton)724 return new ByAngular(getWebDriver()).buttonText(text);725 if (by instanceof ByNGController)726 return new ByAngular(getWebDriver()).controller(text);727 if (by instanceof ByNGModel)728 return new ByAngular(getWebDriver()).model(text);729 if (by instanceof ByNGRepeater)730 return new ByAngular(getWebDriver()).repeater(text);731 if (by instanceof ByNGShow)732 return new ByAngular(getWebDriver()).show(text);733 return null;734 }735 /**736 * Method that return the <b><i>Page</i></b> class737 * @return <b><i>Page</i></b> class738 */739 public Page page() {740 return new Page();741 }742 743 /*744 * Method that returns the instance of the DataWarehouse745 */746 public DataWarehouse data() {...

Full Screen

Full Screen

Source:EventListener.java Github

copy

Full Screen

...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 /*...

Full Screen

Full Screen

Source:LazyWebElement.java Github

copy

Full Screen

...3 */4package com.mifos.testing.framework.webdriver;5import java.util.List;6import java.util.concurrent.TimeUnit;7import org.openqa.selenium.By;8import org.openqa.selenium.Dimension;9import org.openqa.selenium.NoSuchElementException;10import org.openqa.selenium.Point;11import org.openqa.selenium.WebDriver;12import org.openqa.selenium.WebElement;13import org.openqa.selenium.support.ui.ExpectedConditions;14import org.openqa.selenium.support.ui.FluentWait;15import org.openqa.selenium.support.ui.WebDriverWait;16import com.google.common.base.Function;17// TODO: Auto-generated Javadoc18/**19 * The Class LazyWebElement.20 */21public class LazyWebElement implements WebElement {22 /** The locator. */23 By locator;24 /** The timeout. */25 int timeout = 100;26 /** The element. */27 WebElement element = null;28 /** The driver. */29 WebDriver driver;30 /**31 * Checks if is opened.32 *33 * @return true, if is opened34 */35 public boolean isOpened() {36 return true;37 }38 /**39 * Instantiates a new lazy web element.40 *41 * @param driver42 * the driver43 * @param locator44 * the locator45 */46 public LazyWebElement(WebDriver driver, By locator) {47 this.locator = locator;48 this.driver = driver;49 }50 /**51 * Instantiates a new lazy web element.52 *53 * @param driver54 * the driver55 * @param locator56 * the locator57 * @param timeout58 * the timeout59 */60 public LazyWebElement(WebDriver driver, By locator, int timeout) {61 this.locator = locator;62 this.timeout = timeout;63 this.driver = driver;64 }65 /*66 * (non-Javadoc)67 *68 * @see org.openqa.selenium.WebElement#click()69 */70 @Override71 public void click() {72 findWebElement();73 element.click();74 }75 /**76 * Wait and click.77 */78 public void waitAndClick() {79 waitAndfindWebElement();80 element.click();81 }82 /*83 * (non-Javadoc)84 *85 * @see org.openqa.selenium.WebElement#submit()86 */87 @Override88 public void submit() {89 findWebElement();90 element.submit();91 }92 /*93 * (non-Javadoc)94 *95 * @see org.openqa.selenium.WebElement#sendKeys(java.lang.CharSequence[])96 */97 @Override98 public void sendKeys(CharSequence... keysToSend) {99 findWebElement();100 element.sendKeys(keysToSend);101 }102 /*103 * (non-Javadoc)104 *105 * @see org.openqa.selenium.WebElement#clear()106 */107 @Override108 public void clear() {109 findWebElement();110 element.clear();111 }112 /*113 * (non-Javadoc)114 *115 * @see org.openqa.selenium.WebElement#getTagName()116 */117 @Override118 public String getTagName() {119 findWebElement();120 return element.getTagName();121 }122 /*123 * (non-Javadoc)124 *125 * @see org.openqa.selenium.WebElement#getAttribute(java.lang.String)126 */127 @Override128 public String getAttribute(String name) {129 findWebElement();130 return element.getAttribute(name);131 }132 /*133 * (non-Javadoc)134 *135 * @see org.openqa.selenium.WebElement#isSelected()136 */137 @Override138 public boolean isSelected() {139 findWebElement();140 return element.isSelected();141 }142 /*143 * (non-Javadoc)144 *145 * @see org.openqa.selenium.WebElement#isEnabled()146 */147 @Override148 public boolean isEnabled() {149 findWebElement();150 return element.isEnabled();151 }152 /*153 * (non-Javadoc)154 *155 * @see org.openqa.selenium.WebElement#getText()156 */157 @Override158 public String getText() {159 findWebElement();160 return element.getText();161 }162 /*163 * (non-Javadoc)164 *165 * @see org.openqa.selenium.WebElement#findElements(org.openqa.selenium.By)166 */167 @Override168 public List<WebElement> findElements(By by) {169 findWebElement();170 return element.findElements(by);171 }172 /*173 * (non-Javadoc)174 *175 * @see org.openqa.selenium.WebElement#findElement(org.openqa.selenium.By)176 */177 @Override178 public WebElement findElement(By by) {179 findWebElement();180 return element.findElement(by);181 }182 /*183 * (non-Javadoc)184 *185 * @see org.openqa.selenium.WebElement#isDisplayed()186 */187 @Override188 public boolean isDisplayed() {189 findWebElement();190 return element.isDisplayed();191 }192 /*193 * (non-Javadoc)194 *195 * @see org.openqa.selenium.WebElement#getLocation()196 */197 @Override198 public Point getLocation() {199 findWebElement();200 return element.getLocation();201 }202 /*203 * (non-Javadoc)204 *205 * @see org.openqa.selenium.WebElement#getSize()206 */207 @Override208 public Dimension getSize() {209 findWebElement();210 return element.getSize();211 }212 /*213 * (non-Javadoc)214 *215 * @see org.openqa.selenium.WebElement#getCssValue(java.lang.String)216 */217 @Override218 public String getCssValue(String propertyName) {219 findWebElement();220 return element.getCssValue(propertyName);221 }222 /**223 * Find web element.224 */225 private void findWebElement() {226 if (element == null) {227 element = waitForElement((locator), timeout);228 }229 }230 /**231 * Wait andfind web element.232 */233 private void waitAndfindWebElement() {234 if (element == null) {235 element = waitForElementToBeClickable((locator), timeout);236 }237 }238 /**239 * Wait for element.240 *241 * @param locator242 * the locator243 * @param timeout244 * the timeout245 * @return the web element246 */247 private WebElement waitForElement(final By locator, final int timeout) {248 FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver)249 .withTimeout(timeout, TimeUnit.SECONDS)250 .pollingEvery(500, TimeUnit.MILLISECONDS)251 .ignoring(NoSuchElementException.class);252 WebElement element = wait.until(new Function<WebDriver, WebElement>() {253 public WebElement apply(WebDriver driver) {254 return driver.findElement(locator);255 }256 });257 return element;258 }259 /**260 * Wait for element to be clickable.261 *262 * @param locator263 * the locator264 * @param timeout265 * the timeout266 * @return the web element267 */268 private WebElement waitForElementToBeClickable(final By locator, int timeout) {269 WebDriverWait wait = new WebDriverWait(driver, timeout);270 return wait.until(ExpectedConditions.elementToBeClickable(locator));271 }272 /**273 * Gets the locator.274 *275 * @return the locator276 */277 public By getLocator() {278 return locator;279 }280}...

Full Screen

Full Screen

Source:ReportingWebDriverEventListener.java Github

copy

Full Screen

1package com.websoul.qatools.helpers.listeners;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.support.events.WebDriverEventListener;6import org.slf4j.Logger;7import org.slf4j.LoggerFactory;8/**9 * The Class LogDriver.10 */11public class ReportingWebDriverEventListener implements WebDriverEventListener {12 /**13 * The log.14 */15 private static final Logger EVENTS_LOGGER = LoggerFactory.getLogger("ReportingWebDriverEventListener");16 /**17 * Instantiates a new log driver.18 */19 public ReportingWebDriverEventListener() {20 }21 /**22 * Info.23 *24 * @param message the message25 */26 public static void info(String message) {27 EVENTS_LOGGER.info(message);28 }29 /* (non-Javadoc)30 * @see org.openqa.selenium.support.events.ReportingWebDriverEventListener#beforeNavigateTo(java.lang.String, org.openqa.selenium.WebDriver)31 */32 public void beforeNavigateTo(String url, WebDriver driver) {33 }34 /* (non-Javadoc)35 * @see org.openqa.selenium.support.events.ReportingWebDriverEventListener#afterNavigateTo(java.lang.String, org.openqa.selenium.WebDriver)36 */37 public void afterNavigateTo(String url, WebDriver driver) {38 info("Navigate to " + url);39 }40 /* (non-Javadoc)41 * @see org.openqa.selenium.support.events.ReportingWebDriverEventListener#beforeNavigateBack(org.openqa.selenium.WebDriver)42 */43 public void beforeNavigateBack(WebDriver driver) {44 }45 /* (non-Javadoc)46 * @see org.openqa.selenium.support.events.ReportingWebDriverEventListener#afterNavigateBack(org.openqa.selenium.WebDriver)47 */48 public void afterNavigateBack(WebDriver driver) {49 }50 /* (non-Javadoc)51 * @see org.openqa.selenium.support.events.ReportingWebDriverEventListener#beforeNavigateForward(org.openqa.selenium.WebDriver)52 */53 public void beforeNavigateForward(WebDriver driver) {54 }55 /* (non-Javadoc)56 * @see org.openqa.selenium.support.events.ReportingWebDriverEventListener#afterNavigateForward(org.openqa.selenium.WebDriver)57 */58 public void afterNavigateForward(WebDriver driver) {59 }60 @Override61 public void beforeNavigateRefresh(WebDriver webDriver) {62 }63 @Override64 public void afterNavigateRefresh(WebDriver webDriver) {65 }66 /* (non-Javadoc)67 * @see org.openqa.selenium.support.events.ReportingWebDriverEventListener#beforeFindBy(org.openqa.selenium.By, org.openqa.selenium.WebElement, org.openqa.selenium.WebDriver)68 */69 public void beforeFindBy(By by, WebElement element, WebDriver driver) {70 }71 /* (non-Javadoc)72 * @see org.openqa.selenium.support.events.ReportingWebDriverEventListener#afterFindBy(org.openqa.selenium.By, org.openqa.selenium.WebElement, org.openqa.selenium.WebDriver)73 */74 public void afterFindBy(By by, WebElement element, WebDriver driver) {75 }76 /* (non-Javadoc)77 * @see org.openqa.selenium.support.events.ReportingWebDriverEventListener#beforeClickOn(org.openqa.selenium.WebElement, org.openqa.selenium.WebDriver)78 */79 public void beforeClickOn(WebElement element, WebDriver driver) {80 }81 /* (non-Javadoc)82 * @see org.openqa.selenium.support.events.ReportingWebDriverEventListener#afterClickOn(org.openqa.selenium.WebElement, org.openqa.selenium.WebDriver)83 */84 public void afterClickOn(WebElement element, WebDriver driver) {85 String locator = element.toString().substring(element.toString().indexOf(">") + 2, element.toString().lastIndexOf("]"));86 info("The element with locator '" + locator + "' was clicked");87 }88 /* (non-Javadoc)...

Full Screen

Full Screen

By

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.interactions.Actions;6import org.openqa.selenium.Keys;7import java.util.concurrent.TimeUnit;8import org.openqa.selenium.support.ui.WebDriverWait;9import org.openqa.selenium.support.ui.ExpectedConditions;10import org.openqa.selenium.NoSuchElementException;11import org.openqa.selenium.JavascriptExecutor;12import org.openqa.selenium.Alert;13import org.openqa.selenium.support.ui.ExpectedCondition;14import org.openqa.selenium.support.ui.ExpectedConditions;15import java.lang.Thread;16public class Test {17 public static void main(String[] args) {18 WebDriver driver;19 String url;20 WebElement element;21 Actions actions;22 WebDriverWait wait;23 JavascriptExecutor js;24 Alert alert;25 ExpectedCondition condition;26 Boolean booleanCondition;27 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Kishor\\Downloads\\chromedriver_win32\\chromedriver.exe");28 driver = new ChromeDriver();29 driver.manage().window().maximize();

Full Screen

Full Screen

By

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeDriver;4import org.openqa.selenium.support.ui.ExpectedConditions;5import org.openqa.selenium.support.ui.WebDriverWait;6import org.testng.Assert;7import org.testng.annotations.Test;8public class SeleniumTest {9 public void test() {10 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Administrator\\Downloads\\chromedriver_win32\\chromedriver.exe");11 WebDriver driver = new ChromeDriver();12 driver.findElement(By.name("q")).sendKeys("Selenium");13 driver.findElement(By.name("btnK")).click();14 WebDriverWait wait = new WebDriverWait(driver, 10);15 wait.until(ExpectedConditions.titleContains("Selenium"));16 Assert.assertTrue(driver.getTitle().contains("Selenium"));17 driver.quit();18 }19}

Full Screen

Full Screen

By

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.support.ui.Select;6import org.openqa.selenium.support.ui.WebDriverWait;7import org.openqa.selenium.support.ui.ExpectedConditions;8import org.openqa.selenium.support.ui.ExpectedCondition;9import org.openqa.selenium.JavascriptExecutor;10import org.openqa.selenium.interactions.Actions;11import org.openqa.selenium.Keys;12import java.util.List;13import java.util.Set;14import java.util.Iterator;15import java.util.ArrayList;16import java.util.concurrent.TimeUnit;17import java.util.concurrent.TimeoutException;18import java.util.concurrent.Callable;19import java.util.concurrent.ExecutionException;20import java.util.concurrent.FutureTask;21import java.util.concurrent.ThreadLocalRandom;22import java.util.concurrent.atomic.AtomicInteger;23import java.util.concurrent.locks.Lock;24import java.util.concurrent.locks.ReentrantLock;25import java.util.concurrent.locks.ReentrantReadWriteLock;26import java.util.concurrent.locks.ReadWriteLock;27import java.util.concurrent.locks.StampedLock;28import java.util.concurrent.locks.Condition;29import java.util.concurrent.locks.ReentrantLock;30import java.util.concurrent.locks.ReentrantReadWriteLock;31import java.util.concurrent.locks.ReadWriteLock;32import java.util.concurrent.locks.StampedLock;33import java.util.concurrent.locks.Condition;34import java.util.concurrent.locks.ReentrantLock;35import java.util.concurrent.locks.ReentrantReadWriteLock;36import java.util.concurrent.locks.ReadWriteLock;37import java.util.concurrent.locks.StampedLock;38import java.util.concurrent.locks.Condition;39import java.util.concurrent.locks.ReentrantLock;40import java.util.concurrent.locks.ReentrantReadWriteLock;41import java.util.concurrent.locks.ReadWriteLock;42import java.util.concurrent.locks.StampedLock;43import java.util.concurrent.locks.Condition;44import java.util.concurrent.locks.ReentrantLock;45import java.util.concurrent.locks.ReentrantReadWriteLock;46import java.util.concurrent.locks.ReadWriteLock;47import java.util.concurrent.locks.StampedLock;48import java.util.concurrent.locks.Condition;49import java.util.concurrent.locks.ReentrantLock;50import java.util.concurrent.locks.ReentrantReadWriteLock;51import java.util.concurrent.locks.ReadWriteLock;52import java.util.concurrent.locks.StampedLock;53import java.util.concurrent.locks.Condition;54import java.util.concurrent.locks.ReentrantLock;55import java.util.concurrent.locks.ReentrantReadWriteLock;56import java.util.concurrent.locks.ReadWriteLock;57import java.util.concurrent.locks.StampedLock;

Full Screen

Full Screen

By

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5public class FirstSeleniumTest {6public static void main(String[] args) throws InterruptedException {7System.setProperty("webdriver.chrome.driver", "C:\\Users\\Dell\\Desktop\\chromedriver.exe");8WebDriver driver = new ChromeDriver();9System.out.println(driver.getTitle());10WebElement searchBox = driver.findElement(By.name("q"));11searchBox.sendKeys("Selenium");12searchBox.submit();13Thread.sleep(3000);14System.out.println(driver.getTitle());15driver.quit();16}17}

Full Screen

Full Screen

By

Using AI Code Generation

copy

Full Screen

1public class ByClass {2public static void main(String[] args) throws InterruptedException {3System.setProperty("webdriver.chrome.driver", "C:\\Users\\admin\\Downloads\\chromedriver_win32\\chromedriver.exe");4WebDriver driver = new ChromeDriver();5driver.findElement(By.className("gLFyf gsfi")).sendKeys("Selenium");6driver.findElement(By.name("btnK")).click();7driver.findElement(By.linkText("Selenium - Web Browser Automation")).click();8Thread.sleep(5000);9driver.close();10}11}

Full Screen

Full Screen

By

Using AI Code Generation

copy

Full Screen

1By by = By.className("classname");2By by = new ByClassName("classname");3By.cssSelector(String cssSelector): # Language: markdown4By by = By.cssSelector("cssSelector");5By by = new ByCssSelector("cssSelector");6By.id(String id): # Language: markdown7By by = By.id("id");8By by = new ById("id");9By.linkText(String linkText): # Language: markdown10By by = By.linkText("linkText");11By by = new ByLinkText("linkText");12By.name(String name): # Language: markdown13By by = By.name("name");14By by = new ByName("name");15By.partialLinkText(String partialLinkText): # Language: markdown16By by = By.partialLinkText("partialLinkText");17By by = new ByPartialLinkText("partialLinkText");18By.tagName(String tagName): # Language: markdown19By by = By.tagName("tagName");20By by = new ByTagName("tagName");21By.xpath(String xpath): # Language: markdown22By by = By.xpath("xpath");23By by = new ByXPath("xpath");24ByChained(By... bys): # Language: markdown25By by = By.className("classname");26By by = new ByChained(new ByClassName("classname"));27ByIdOrName(String idOrName): # Language:

Full Screen

Full Screen
copy
1<plugins>2 <plugin> 3 <artifactId>maven-compiler-plugin</artifactId>4 <configuration>5 <source>1.8</source>6 <target>1.8</target>7 </configuration>8 </plugin>9</plugins>10
Full Screen
copy
1<properties>2 <maven.compiler.target>1.8</maven.compiler.target>3 <maven.compiler.source>1.8</maven.compiler.source>4</properties>5
Full Screen
copy
1<properties>2 <maven.compiler.source>12</maven.compiler.source>3 <maven.compiler.target>12</maven.compiler.target>4</properties>5<build>6 <plugins>7 <plugin>8 <groupId>org.apache.maven.plugins</groupId>9 <artifactId>maven-compiler-plugin</artifactId>10 <version>3.8.1</version>11 <configuration>12 <release>12</release>13 </configuration>14 </plugin>15 </plugins>16</build>17
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