Source:What does "Could not find or load main class" mean?
// a = b + c
Complex a, b, c; a = b.add(c);
Best Selenium code snippet using org.openqa.selenium.interactions.Interface Interactive
Source:DefaultFieldDecoratorTest.java
1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.support.pagefactory;18import static org.hamcrest.Matchers.is;19import static org.hamcrest.Matchers.notNullValue;20import static org.hamcrest.Matchers.nullValue;21import static org.junit.Assert.assertThat;22import static org.mockito.Matchers.any;23import static org.mockito.Mockito.mock;24import static org.mockito.Mockito.verify;25import static org.mockito.Mockito.when;26import org.junit.Test;27import org.junit.runner.RunWith;28import org.junit.runners.JUnit4;29import org.openqa.selenium.By;30import org.openqa.selenium.WebDriver;31import org.openqa.selenium.WebElement;32import org.openqa.selenium.interactions.Actions;33import org.openqa.selenium.interactions.HasInputDevices;34import org.openqa.selenium.interactions.Interactive;35import org.openqa.selenium.interactions.Mouse;36import org.openqa.selenium.interactions.internal.Coordinates;37import org.openqa.selenium.internal.FindsById;38import org.openqa.selenium.internal.FindsByLinkText;39import org.openqa.selenium.internal.FindsByName;40import org.openqa.selenium.internal.FindsByXPath;41import org.openqa.selenium.interactions.internal.Locatable;42import org.openqa.selenium.internal.WrapsElement;43import org.openqa.selenium.support.FindAll;44import org.openqa.selenium.support.FindBy;45import org.openqa.selenium.support.FindBys;46import org.openqa.selenium.support.PageFactory;47import java.lang.reflect.Field;48import java.util.List;49@RunWith(JUnit4.class)50public class DefaultFieldDecoratorTest {51 // Unusued fields are used by tests. Do not remove!52 @SuppressWarnings("unused") private WebElement element1;53 @SuppressWarnings("unused") private WebElement element2;54 @SuppressWarnings("unused") private List<WebElement> list1;55 @SuppressWarnings("unused") private List<Object> list2;56 @SuppressWarnings("unused") private Integer num;57 @SuppressWarnings("unused")58 @FindBy(tagName = "div")59 private List<WebElement> list3;60 @SuppressWarnings("unused")61 @FindBys({@FindBy(tagName = "div"), @FindBy(tagName = "a")})62 private List<WebElement> list4;63 @SuppressWarnings("unused")64 @FindAll({@FindBy(tagName = "div"), @FindBy(tagName = "a")})65 private List<WebElement> list5;66 @SuppressWarnings("unused")67 @FindBy(tagName = "div")68 private List<Object> list6;69 @SuppressWarnings("unused")70 @FindBys({@FindBy(tagName = "div"), @FindBy(tagName = "a")})71 private List<Object> list7;72 @SuppressWarnings("unused")73 @FindAll({@FindBy(tagName = "div"), @FindBy(tagName = "a")})74 private List<Object> list8;75 private FieldDecorator createDecoratorWithNullLocator() {76 return new DefaultFieldDecorator(new ElementLocatorFactory() {77 public ElementLocator createLocator(Field field) {78 return null;79 }80 });81 }82 private FieldDecorator createDecoratorWithDefaultLocator() {83 return new DefaultFieldDecorator(84 new DefaultElementLocatorFactory(null));85 }86 @Test87 public void decoratesWebElement() throws Exception {88 FieldDecorator decorator = createDecoratorWithDefaultLocator();89 assertThat(decorator.decorate(getClass().getClassLoader(),90 getClass().getDeclaredField("element1")),91 is(notNullValue()));92 assertThat(decorator.decorate(getClass().getClassLoader(),93 getClass().getDeclaredField("element2")),94 is(notNullValue()));95 }96 @Test97 public void decoratesAnnotatedWebElementList() throws Exception {98 FieldDecorator decorator = createDecoratorWithDefaultLocator();99 assertThat(decorator.decorate(getClass().getClassLoader(),100 getClass().getDeclaredField("list3")),101 is(notNullValue()));102 assertThat(decorator.decorate(getClass().getClassLoader(),103 getClass().getDeclaredField("list4")),104 is(notNullValue()));105 assertThat(decorator.decorate(getClass().getClassLoader(),106 getClass().getDeclaredField("list5")),107 is(notNullValue()));108 }109 @Test110 public void doesNotDecorateNonAnnotatedWebElementList() throws Exception {111 FieldDecorator decorator = createDecoratorWithDefaultLocator();112 assertThat(decorator.decorate(getClass().getClassLoader(),113 getClass().getDeclaredField("list1")),114 is(nullValue()));115 assertThat(decorator.decorate(getClass().getClassLoader(),116 getClass().getDeclaredField("list2")),117 is(nullValue()));118 }119 @Test120 public void doesNotDecorateNonWebElement() throws Exception {121 FieldDecorator decorator = createDecoratorWithDefaultLocator();122 assertThat(decorator.decorate(getClass().getClassLoader(),123 getClass().getDeclaredField("num")),124 is(nullValue()));125 }126 @Test127 public void doesNotDecorateListOfSomethingElse() throws Exception {128 FieldDecorator decorator = createDecoratorWithDefaultLocator();129 assertThat(decorator.decorate(getClass().getClassLoader(),130 getClass().getDeclaredField("list6")),131 is(nullValue()));132 assertThat(decorator.decorate(getClass().getClassLoader(),133 getClass().getDeclaredField("list7")),134 is(nullValue()));135 assertThat(decorator.decorate(getClass().getClassLoader(),136 getClass().getDeclaredField("list8")),137 is(nullValue()));138 }139 @Test140 public void doesNotDecorateNullLocator() throws Exception {141 FieldDecorator decorator = createDecoratorWithNullLocator();142 assertThat(decorator.decorate(getClass().getClassLoader(),143 getClass().getDeclaredField("element1")),144 is(nullValue()));145 assertThat(decorator.decorate(getClass().getClassLoader(),146 getClass().getDeclaredField("element2")),147 is(nullValue()));148 assertThat(decorator.decorate(getClass().getClassLoader(),149 getClass().getDeclaredField("list1")),150 is(nullValue()));151 assertThat(decorator.decorate(getClass().getClassLoader(),152 getClass().getDeclaredField("list2")),153 is(nullValue()));154 assertThat(decorator.decorate(getClass().getClassLoader(),155 getClass().getDeclaredField("num")),156 is(nullValue()));157 }158 @Test159 public void testDecoratingProxyImplementsRequiredInterfaces() throws Exception {160 final AllDriver driver = mock(AllDriver.class);161 final AllElement element = mock(AllElement.class);162 final Mouse mouse = mock(Mouse.class);163 when(driver.getMouse()).thenReturn(mouse);164 when(element.getCoordinates()).thenReturn(mock(Coordinates.class));165 when(driver.findElement(By.id("foo"))).thenReturn(element);166 Page page = new Page();167 PageFactory.initElements(driver, page);168 new Actions(driver).moveToElement(page.foo).build().perform();169 verify(driver).getKeyboard();170 verify(driver).getMouse();171 verify(element).getCoordinates();172 verify(mouse).mouseMove(any(Coordinates.class));173 }174 private static class Page {175 @FindBy(id = "foo")176 public WebElement foo;177 }178 private interface AllDriver extends WebDriver, FindsById, FindsByLinkText, FindsByName,179 FindsByXPath, HasInputDevices {180 // Place holder181 }182 private interface AllElement extends WebElement, WrapsElement, Locatable {183 // Place holder184 }185}...
Source:ComponentWebDriver.java
1/*2 * Copyright © 2021 the original author or authors.3 *4 * Licensed under the The MIT License (MIT) (the "License");5 * You may obtain a copy of the License at6 *7 * https://mit-license.org/8 *9 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software10 * and associated documentation files (the âSoftwareâ), to deal in the Software without11 * restriction, including without limitation the rights to use, copy, modify, merge, publish,12 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the13 * Software is furnished to do so, subject to the following conditions:14 *15 * The above copyright notice and this permission notice shall be included in all copies or16 * substantial portions of the Software.17 *18 * THE SOFTWARE IS PROVIDED âAS ISâ, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING19 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23 */24package com.github.grossopa.selenium.core;25import com.github.grossopa.selenium.core.component.WebComponent;26import org.openqa.selenium.*;27import org.openqa.selenium.interactions.Actions;28import org.openqa.selenium.interactions.HasInputDevices;29import org.openqa.selenium.interactions.Interactive;30import org.openqa.selenium.support.ui.WebDriverWait;31import java.util.List;32import java.util.function.Function;33/**34 * An encapsulated {@link WebDriver} instance that supports to get the web element as {@link WebComponent}.35 *36 * @author Jack Yin37 * @since 1.038 */39@SuppressWarnings("deprecation")40public interface ComponentWebDriver41 extends WrapsDriver, WebDriver, JavascriptExecutor, HasInputDevices, HasCapabilities, Interactive,42 TakesScreenshot {43 /**44 * Finds all elements within the current page using the given mechanism and encapsulate the {@link WebElement} list45 * into {@link WebComponent}.46 * <p>47 * This method is affected by the 'implicit wait' times in force at the time of execution. When implicitly waiting,48 * this method will return as soon as there are more than 0 items in the found collection, or will return an empty49 * list if the timeout is reached.50 * </p>51 *52 * @param by The locating mechanism to use53 * @return A list of all {@link WebComponent}s, or an empty list if nothing matches54 * @see org.openqa.selenium.By55 * @see org.openqa.selenium.WebDriver.Timeouts56 */57 List<WebComponent> findComponents(By by);58 /**59 * Find the first {@link WebElement} using the given method and encapsulate it into {@link T} which is sub type of60 * WebComponent.61 * <p>62 * This method is affected by the 'implicit wait' times in force at the time of execution. The findElement(..)63 * invocation will return a matching row, or try again repeatedly until the configured timeout is reached.64 * </p>65 * <p>66 * findElement should not be used to look for non-present elements, use {@link #findComponents(By)} and assert zero67 * length response instead.68 * </p>69 *70 * @param by The locating mechanism71 * @param mappingFunction the mapping function to convert {@link WebComponent} to {@link T}.72 * @param <T> the target type73 * @return The first matching element on the current page74 * @throws NoSuchElementException If no matching elements are found75 * @see org.openqa.selenium.By76 * @see org.openqa.selenium.WebDriver.Timeouts77 */78 <T> T findComponentAs(By by, Function<WebComponent, T> mappingFunction);79 /**80 * Finds all elements within the current page using the given mechanism and encapsulate the {@link WebElement} list81 * into {@link T} which is sub type of WebComponent.82 * <p>83 * This method is affected by the 'implicit wait' times in force at the time of execution. When implicitly waiting,84 * this method will return as soon as there are more than 0 items in the found collection, or will return an empty85 * list if the timeout is reached.86 * </p>87 *88 * @param by The locating mechanism to use89 * @param mappingFunction the mapping function to convert {@link WebComponent} to {@link T}.90 * @param <T> the target type91 * @return A list of all {@link WebComponent}s, or an empty list if nothing matches92 * @see org.openqa.selenium.By93 * @see org.openqa.selenium.WebDriver.Timeouts94 */95 <T> List<T> findComponentsAs(By by, Function<WebComponent, T> mappingFunction);96 /**97 * Find the first {@link WebElement} using the given method and encapsulate it into {@link WebComponent}.98 * <p>99 * This method is affected by the 'implicit wait' times in force at the time of execution. The findElement(..)100 * invocation will return a matching row, or try again repeatedly until the configured timeout is reached.101 * </p>102 * <p>103 * findElement should not be used to look for non-present elements, use {@link #findComponents(By)} and assert zero104 * length response instead.105 * </p>106 *107 * @param by The locating mechanism108 * @return The first matching element on the current page109 * @throws NoSuchElementException If no matching elements are found110 * @see org.openqa.selenium.By111 * @see org.openqa.selenium.WebDriver.Timeouts112 */113 WebComponent findComponent(By by);114 /**115 * deprecated, in favor of {@link #findComponents(By)}116 *117 * @param by The locating mechanism to use118 * @return A list of all {@link WebElement}s, or an empty list if nothing matches119 * @deprecated in favor of {@link #findComponents(By)}120 */121 @Deprecated(since = "1.0")122 List<WebElement> findElements(By by);123 /**124 * deprecated, in favor of {@link #findComponent(By)}125 *126 * @param by The locating mechanism to use127 * @return A list of all {@link WebElement}s, or an empty list if nothing matches128 * @deprecated in favor of {@link #findComponent(By)}129 */130 @Deprecated(since = "1.0")131 WebElement findElement(By by);132 /**133 * Maps a given {@link WebElement} to {@link WebComponent}.134 *135 * @param element the element instance to map136 * @return the mapped {@link WebComponent} instance137 */138 WebComponent mapElement(WebElement element);139 /**140 * A shortcut for {@code new Actions(driver);}141 *142 * @return the created Actions instance143 */144 Actions createActions();145 /**146 * A shortcut to create new instance of {@link WebDriverWait} with milliseconds.147 *148 * @param timeOutInMilliseconds the timeout in milliseconds149 * @return the created {@link WebDriverWait} instance.150 */151 WebDriverWait createWait(long timeOutInMilliseconds);152 /**153 * Move mouse to the element. shortcut of {@code createActions().moveToElement(element).perform()}154 *155 * @param element the element to move to.156 */157 void moveTo(WebElement element);158 /**159 * A neat solution for scrolling to an element160 *161 * @param element the element to scroll to162 */163 void scrollTo(WebElement element);164 /**165 * Sleeps current thread in millisecond166 *167 * @param millis the time to sleep in millisecond, if negative or 0 then doing nothing168 */169 void threadSleep(long millis);170}...
Source:Interactive.java
1package org.openqa.selenium.interactions;2import java.util.Collection;3public abstract interface Interactive4{5 public abstract void perform(Collection<Sequence> paramCollection);6 7 public abstract void resetInputState();8}...
Interface Interactive
Using AI Code Generation
1import org.openqa.selenium.interactions.Actions;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.By;5import org.openqa.selenium.chrome.ChromeDriver;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.JavascriptExecutor;11import org.openqa.selenium.WebElement;12import java.util.List;13import java.io.File;14import java.io.FileInputStream;15import java.util.Properties;16import org.openqa.selenium.interactions.Actions;17public class SeleniumTest {18 public static void main(String[] args) throws InterruptedException {19 Properties prop = new Properties();20 try {21 prop.load(new FileInputStream(new File("config.properties")));22 } catch (Exception e) {23 e.printStackTrace();24 }25 System.setProperty("webdriver.chrome.driver", "C:\\Users\\shiva\\Downloads\\chromedriver_win32\\chromedriver.exe");26 WebDriver driver = new ChromeDriver();27 driver.manage().window().maximize();28 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Interface Interactive
Using AI Code Generation
1package com.qa.selenium;2import java.util.concurrent.TimeUnit;3import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.chrome.ChromeDriver;7import org.openqa.selenium.interactions.Actions;8import org.testng.annotations.AfterTest;9import org.testng.annotations.BeforeTest;10import org.testng.annotations.Test;11public class MouseHoverActions {12 WebDriver driver;13 public void setUp() {14 System.setProperty("webdriver.chrome.driver", "F:\\Selenium\\chromedriver.exe");15 driver = new ChromeDriver();16 driver.manage().window().maximize();17 driver.manage().deleteAllCookies();18 driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);19 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);20 }21 public void mouseHoverTest() {22 Actions action = new Actions(driver);23 action.moveToElement(mainMenu).build().perform();24 subMenu.click();25 }26 public void tearDown() {27 driver.quit();28 }29}
Interface Interactive
Using AI Code Generation
1package com.selenium;2import org.openqa.selenium.By;3import org.openqa.selenium.Keys;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.chrome.ChromeDriver;7import org.openqa.selenium.interactions.Actions;8public class ActiTime {9public static void main(String[] args) throws InterruptedException {10System.setProperty("webdriver.chrome.driver","C:\\Users\\Srikanth\\Desktop\\Selenium\\chromedriver_win32\\chromedriver.exe");11WebDriver driver = new ChromeDriver();12Thread.sleep(2000);13Actions act = new Actions(driver);14WebElement link = driver.findElement(By.linkText("actiTIME Inc."));15act.moveToElement(link).keyDown(Keys.CONTROL).click().keyUp(Keys.CONTROL).build().perform();16}17}
Interface Interactive
Using AI Code Generation
1import org.openqa.selenium.interactions.Actions;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.By;6public class ActionsClass {7public static void main(String[] args) throws InterruptedException {8System.setProperty("webdriver.chrome.driver", "C:\\Users\\admin\\Downloads\\chromedriver_win32\\chromedriver.exe");9WebDriver driver = new ChromeDriver();10driver.manage().window().maximize();11Actions act = new Actions(driver);12act.moveToElement(ele).build().perform();13Thread.sleep(5000);14act.moveToElement(ele1).click().build().perform();15Thread.sleep(5000);16act.moveToElement(ele2).click().build().perform();17Thread.sleep(5000);18driver.close();19}20}
Interface Interactive
Using AI Code Generation
1import org.openqa.selenium.*;2import org.openqa.selenium.chrome.*;3import org.openqa.selenium.interactions.*;4import java.util.concurrent.TimeUnit;5public class MouseHover {6public static void main(String[] args) {7System.setProperty("webdriver.chrome.driver","C:\\Users\\User\\Downloads\\chromedriver_win32\\chromedriver.exe");8WebDriver driver=new ChromeDriver();9driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);10Actions action=new Actions(driver);11action.moveToElement(driver.findElement(By.linkText("SUPPORT"))).build().perform();12driver.findElement(By.linkText("Contact Us")).click();13driver.close();14}15}
1// a = b + c2Complex a, b, c; a = b.add(c);3
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.
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.
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.
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.
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.
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.
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.
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.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!