org.openqa.selenium.remote.RemoteWebElement Java Examples

The following examples show how to use org.openqa.selenium.remote.RemoteWebElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsonToMobileElementConverter.java    From java-client with Apache License 2.0 6 votes vote down vote up
@Override
protected RemoteWebElement newRemoteWebElement() {
    Class<? extends RemoteWebElement> target;
    target = getElementClass(platform, automation);

    try {
        Constructor<? extends RemoteWebElement> constructor = target.getDeclaredConstructor();
        constructor.setAccessible(true);
        RemoteWebElement result = constructor.newInstance();

        result.setParent(driver);
        result.setFileDetector(driver.getFileDetector());

        return result;
    } catch (Exception e) {
        throw new WebDriverException(e);
    }
}
 
Example #2
Source File: Edition108_iOS_Home_Screen_Actions.java    From appiumpro with Apache License 2.0 6 votes vote down vote up
@Test
public void testHomeActions() {
    WebDriverWait wait = new WebDriverWait(driver, 10);

    // press home button twice to make sure we are on the page with reminders
    ImmutableMap<String, String> pressHome = ImmutableMap.of("name", "home");
    driver.executeScript("mobile: pressButton", pressHome);
    driver.executeScript("mobile: pressButton", pressHome);

    // find the reminders icon and long-press it
    WebElement homeIcon = wait.until(ExpectedConditions.presenceOfElementLocated(REMINDER_ICON));
    driver.executeScript("mobile: touchAndHold", ImmutableMap.of(
        "element", ((RemoteWebElement)homeIcon).getId(),
        "duration", 2.0
    ));

    // now find the home action using the appropriate accessibility id
    wait.until(ExpectedConditions.presenceOfElementLocated(ADD_REMINDER)).click();

    // prove we opened up the reminders app to the view where we can add a reminder
    wait.until(ExpectedConditions.presenceOfElementLocated(LISTS));
}
 
Example #3
Source File: ByExtended.java    From stevia with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void fixLocator(SearchContext context, String cssLocator,
		WebElement element) {

	if (element instanceof RemoteWebElement) {
		try {
			@SuppressWarnings("rawtypes")
			Class[] parameterTypes = new Class[] { SearchContext.class,
					String.class, String.class };
			Method m = element.getClass().getDeclaredMethod(
					"setFoundBy", parameterTypes);
			m.setAccessible(true);
			Object[] parameters = new Object[] { context,
					"css selector", cssLocator };
			m.invoke(element, parameters);
		} catch (Exception fail) {
			//NOOP Would like to log here? 
		}
	}
}
 
Example #4
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void findElementGetsTheSameElementBetweenWindowCalls() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    String id1 = ((RemoteWebElement) element1).getId();
    driver.switchTo().window(titleOfWindow);
    WebElement element2 = driver.findElement(By.name("click-me"));
    String id2 = ((RemoteWebElement) element2).getId();
    AssertJUnit.assertEquals(id1, id2);
}
 
Example #5
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void getLocationInView() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    try {
        ((RemoteWebElement) element1).getCoordinates().inViewPort();
        throw new MissingException(WebDriverException.class);
    } catch (WebDriverException e) {
    }
}
 
Example #6
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void windowTitleWithPercentage() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setTitle("My %Dialog%");
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("click-me"));
    String id1 = ((RemoteWebElement) element1).getId();
    // driver.switchTo().window("My %25Dialog%25");
    TargetLocator switchTo = driver.switchTo();
    switchTo.window("My %Dialog%");
    WebElement element2 = driver.findElement(By.name("click-me"));
    String id2 = ((RemoteWebElement) element2).getId();
    AssertJUnit.assertEquals(id1, id2);
}
 
Example #7
Source File: UIElement.java    From functional-tests-core with Apache License 2.0 6 votes vote down vote up
public void doubleTap() {
    LOGGER_BASE.info("Double Tap: "); // + Elements.getElementDetails(element));
    if (this.settings.platform == PlatformType.Android) {

        Double x = (double) this.element.getLocation().x
                + (double) (this.element.getSize().width / 2);
        Double y = (double) this.element.getLocation().y
                + (double) (this.element.getSize().height / 2);
        JavascriptExecutor js = (JavascriptExecutor) this.client.driver;
        HashMap<String, Double> tapObject = new HashMap<String, Double>();
        tapObject.put("x", x);
        tapObject.put("y", y);
        tapObject.put("touchCount", (double) 1);
        tapObject.put("tapCount", (double) 1);
        tapObject.put("duration", 0.05);
        js.executeScript("mobile: tap", tapObject);
        js.executeScript("mobile: tap", tapObject);
    }
    if (this.settings.platform == PlatformType.iOS) {
        RemoteWebElement e = (RemoteWebElement) this.element;
        ((RemoteWebDriver) this.client.driver).executeScript("au.getElement('" + e.getId() + "').tapWithOptions({tapCount:2});");
    }
}
 
Example #8
Source File: QAFExtendedWebElement.java    From qaf with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Object apply(Object result) {
	if (result instanceof Collection<?>) {
		Collection<QAFExtendedWebElement> results = (Collection<QAFExtendedWebElement>) result;
		return Lists.newArrayList(Iterables.transform(results, this));
	}

	result = super.apply(result);
	if (result instanceof RemoteWebElement) {
		if (!(result instanceof QAFExtendedWebElement)) {
			QAFExtendedWebElement ele = newRemoteWebElement();
			ele.setId(((RemoteWebElement) result).getId());
			return ele;
		}
	}
	return result;
}
 
Example #9
Source File: UsingPageFactoryTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecoratedElementsShouldBeUnwrapped() {
  final RemoteWebElement element = new RemoteWebElement();
  element.setId("foo");

  WebDriver driver = mock(WebDriver.class);
  when(driver.findElement(new ByIdOrName("element"))).thenReturn(element);

  PublicPage page = new PublicPage();
  PageFactory.initElements(driver, page);

  Object seen = new WebElementToJsonConverter().apply(page.element);
  Object expected = new WebElementToJsonConverter().apply(element);

  assertThat(seen).isEqualTo(expected);
}
 
Example #10
Source File: WebElementToJsonConverterTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void convertsAListWithAWebElement() {
  RemoteWebElement element = new RemoteWebElement();
  element.setId("abc123");

  RemoteWebElement element2 = new RemoteWebElement();
  element2.setId("anotherId");

  Object value = CONVERTER.apply(asList(element, element2));
  assertThat(value).isInstanceOf(Collection.class);

  List<Object> list = new ArrayList<>((Collection<Object>) value);
  assertThat(list).hasSize(2);
  assertIsWebElementObject(list.get(0), "abc123");
  assertIsWebElementObject(list.get(1), "anotherId");
}
 
Example #11
Source File: PointerInputTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void encodesWrappedElementInMoveOrigin() {
  RemoteWebElement innerElement = new RemoteWebElement();
  innerElement.setId("12345");
  WebElement element = new WrappedWebElement(innerElement);

  PointerInput pointerInput = new PointerInput(Kind.MOUSE, null);
  Interaction move = pointerInput.createPointerMove(
      Duration.ofMillis(100), Origin.fromElement(element), 0, 0);
  Sequence sequence = new Sequence(move.getSource(), 0).addAction(move);

  String rawJson = new Json().toJson(sequence);
  ActionSequenceJson json = new Json().toType(
      rawJson,
      ActionSequenceJson.class,
      PropertySetting.BY_FIELD);

  assertThat(json.actions).hasSize(1);
  ActionJson firstAction = json.actions.get(0);
  assertThat(firstAction.origin).containsEntry(W3C.getEncodedElementKey(), "12345");
}
 
Example #12
Source File: Shadow.java    From shadow-automation-selenium with Apache License 2.0 6 votes vote down vote up
private void fixLocator(SearchContext context, String cssLocator, WebElement element) {
	if (element instanceof RemoteWebElement) {
		try {
		@SuppressWarnings("rawtypes")
		Class[] parameterTypes = new Class[] { SearchContext.class,
		        String.class, String.class };
		Method m = element.getClass().getDeclaredMethod(
		        "setFoundBy", parameterTypes);
		m.setAccessible(true);
		Object[] parameters = new Object[] { context, "cssSelector", cssLocator };
		m.invoke(element, parameters);
		} catch (Exception fail) {
			//fail("Something bad happened when fixing locator");
		}
	}
}
 
Example #13
Source File: EvernoteAndroidTest.java    From candybean with GNU Affero General Public License v3.0 5 votes vote down vote up
@Ignore
@Test
public void deleteAllNotes() throws CandybeanException {
	openNotes();
	List<WebElement> notes = iface.wd.findElements(By
			.id("com.evernote:id/title"));
	while (notes.size() != 0) {
		WebElement note = notes.get(0);
		HashMap<String, String> values = new HashMap<String, String>();
		values.put("element", ((RemoteWebElement) note).getId());
		((JavascriptExecutor) iface.wd).executeScript("mobile: longClick", values);
		iface.pause(1000);
		WebElement footer = ((RemoteWebDriver) iface.wd)
				.findElementById("com.evernote:id/efab_menu_footer");
		List<WebElement> footerItems = footer.findElements(By
				.className("android.widget.ImageButton"));
		WebElement moreOptions = footerItems.get(footerItems.size() - 1);
		moreOptions.click();
		iface.pause(1000);
		WebElement deleteButton = iface.wd.findElements(
				By.id("com.evernote:id/item_title")).get(5);
		deleteButton.click();
		iface.pause(1000);
		WebElement deleteConfirmation = iface.wd.findElement(By
				.id("android:id/button1"));
		deleteConfirmation.click();
		iface.pause(1000);
		notes = iface.wd.findElements(By.id("com.evernote:id/title"));
	}
	assertEquals(iface.wd.findElements(By.id("com.evernote:id/title")).size(), 0);
}
 
Example #14
Source File: WebElementToJsonConverterTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void convertsAMapWithAWebElement() {
  RemoteWebElement element = new RemoteWebElement();
  element.setId("abc123");

  Object value = CONVERTER.apply(ImmutableMap.of("one", element));
  assertThat(value).isInstanceOf(Map.class);

  Map<String, Object> map = (Map<String, Object>) value;
  assertThat(map.size()).isEqualTo(1);
  assertIsWebElementObject(map.get("one"), "abc123");
}
 
Example #15
Source File: WebElementToJsonConverterTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void convertsRemoteWebElementToWireProtocolMap() {
  RemoteWebElement element = new RemoteWebElement();
  element.setId("abc123");

  Object value = CONVERTER.apply(element);
  assertIsWebElementObject(value, "abc123");
}
 
Example #16
Source File: ArgumentConverter.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
public Object apply(Object arg) {
  if (arg instanceof Map) {
    @SuppressWarnings("unchecked")
    Map<String, Object> paramAsMap = (Map<String, Object>) arg;
    if (paramAsMap.containsKey("ELEMENT")) {
      KnownElements.ProxiedElement element = (KnownElements.ProxiedElement) knownElements
          .get((String) paramAsMap.get("ELEMENT"));
      return element.getWrappedElement();
    }

    Map<String, Object> converted = new HashMap<>(paramAsMap.size());
    for (Map.Entry<String, Object> entry : paramAsMap.entrySet()) {
      converted.put(entry.getKey(), apply(entry.getValue()));
    }
    return converted;
  }

  if (arg instanceof RemoteWebElement) {
    return knownElements.get(((RemoteWebElement) arg).getId());
  }

  if (arg instanceof List<?>) {
    return Lists.newArrayList(Iterables.transform((List<?>) arg, this));
  }

  return arg;
}
 
Example #17
Source File: ElementEqualityTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
private String getId(WebElement element) {
  if (!(element instanceof RemoteWebElement)) {
    System.err.println("Skipping remote element equality test - not a remote web driver");
    return null;
  }

  return ((RemoteWebElement) element).getId();
}
 
Example #18
Source File: JsonHttpResponseCodecTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConvertElementReferenceToRemoteWebElement() {
  HttpResponse response = new HttpResponse();
  response.setStatus(HTTP_OK);
  response.setContent(asJson(ImmutableMap.of(
      "status", 0,
      "value", ImmutableMap.of(Dialect.OSS.getEncodedElementKey(), "345678"))));

  Response decoded = codec.decode(response);
  assertThat(((RemoteWebElement) decoded.getValue()).getId()).isEqualTo("345678");
}
 
Example #19
Source File: WebElementToJsonConverterTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void convertsAnArrayWithAWebElement() {
  RemoteWebElement element = new RemoteWebElement();
  element.setId("abc123");

  Object value = CONVERTER.apply(new Object[] { element });
  assertContentsInOrder(new ArrayList<>((Collection<?>) value),
      ImmutableMap.of(
        Dialect.OSS.getEncodedElementKey(), "abc123",
        Dialect.W3C.getEncodedElementKey(), "abc123"));
}
 
Example #20
Source File: WebElementToJsonConverterTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Test
public void unwrapsWrappedElements_multipleLevelsOfWrapping() {
  RemoteWebElement element = new RemoteWebElement();
  element.setId("abc123");

  WrappedWebElement wrapped = wrapElement(element);
  wrapped = wrapElement(wrapped);
  wrapped = wrapElement(wrapped);
  wrapped = wrapElement(wrapped);

  Object value = CONVERTER.apply(wrapped);
  assertIsWebElementObject(value, "abc123");
}
 
Example #21
Source File: AndroidMobileCommandHelper.java    From java-client with Apache License 2.0 5 votes vote down vote up
/**
 * This method forms a {@link Map} of parameters for the element
 * value replacement. It is used against input elements
 *
 * @param remoteWebElement an instance which contains an element ID
 * @param value a new value
 * @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
 */
public static Map.Entry<String, Map<String, ?>>  replaceElementValueCommand(
    RemoteWebElement remoteWebElement, String value) {
    String[] parameters = new String[] {"id", "value"};
    Object[] values =
        new Object[] {remoteWebElement.getId(), value};

    return new AbstractMap.SimpleEntry<>(
            REPLACE_VALUE, prepareArguments(parameters, values));
}
 
Example #22
Source File: WebDriverUtilTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testWrappedWebElementUnwrap()
{
    RemoteWebElement remoteWebElement = mock(RemoteWebElement.class);
    WrapsDriver actual = WebDriverUtil.unwrap(new TextFormattingWebElement(remoteWebElement), WrapsDriver.class);
    assertEquals(remoteWebElement, actual);
}
 
Example #23
Source File: JsonToMobileElementConverter.java    From java-client with Apache License 2.0 5 votes vote down vote up
@Override
public Object apply(Object result) {
    Object toBeReturned = result;
    if (toBeReturned instanceof RemoteWebElement) {
        toBeReturned = newRemoteWebElement();
        ((RemoteWebElement) toBeReturned).setId(((RemoteWebElement) result).getId());
    }

    return super.apply(toBeReturned);
}
 
Example #24
Source File: WebElementConverter.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
protected CachingRemoteWebElement createCachingWebElement(RemoteWebElement originalElement) {
    CachingRemoteWebElement element = new CachingRemoteWebElement(originalElement);
    // ensure we always set the correct parent and file detector
    element.setParent(driver);
    element.setFileDetector(driver.getFileDetector());
    return element;
}
 
Example #25
Source File: WebElementConverter.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
@Override
public Object apply(Object result) {
    if (result instanceof RemoteWebElement
            && !(result instanceof CachingRemoteWebElement)) {
        RemoteWebElement originalElement = (RemoteWebElement) result;
        result = createCachingWebElement(originalElement);
    }
    return super.apply(result);
}
 
Example #26
Source File: AppPage.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
protected void fillFileBox(RemoteWebElement fileBoxElement, String fileName) {
    if (fileName.isEmpty()) {
        fileBoxElement.clear();
    } else {
        fileBoxElement.setFileDetector(new UselessFileDetector());
        String newFilePath = new File(fileName).getAbsolutePath();
        fileBoxElement.sendKeys(newFilePath);
    }
}
 
Example #27
Source File: AppPage.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
protected void fillFileBox(RemoteWebElement fileBoxElement, String fileName) {
    if (fileName.isEmpty()) {
        fileBoxElement.clear();
    } else {
        fileBoxElement.setFileDetector(new UselessFileDetector());
        String filePath = new File(fileName).getAbsolutePath();
        fileBoxElement.sendKeys(filePath);
    }
}
 
Example #28
Source File: PtlWebDriver.java    From hifive-pitalium with Apache License 2.0 5 votes vote down vote up
private RemoteWebElement setOwner(RemoteWebElement element) {
	if (driver != null) {
		element.setParent(driver);
		element.setFileDetector(driver.getFileDetector());
	}
	return element;
}
 
Example #29
Source File: ChromeDriverClient.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
public boolean tap(By by) {
	try {
		Map<String, ?> params = ImmutableMap.of("element", ((RemoteWebElement)driver.findElement(by)).getId());
		((RobotRemoteWebDriver)this.driver).execute(DriverCommand.TOUCH_SINGLE_TAP, params);
	}catch(Exception ex) {
		return false;
	}
	return true;
}
 
Example #30
Source File: CodeEditorHandlerThread.java    From collect-earth with MIT License 5 votes vote down vote up
private void disableAutoComplete() {
	// Display the settings in Google Earth Engine Code Editor (this emulates
	// clicking on the settings icon)
	webDriverGee.findElementByClassName("settings-menu-button").click();
	// Get the Div that is the parent of the one with text that contains
	// Autocomplete
	RemoteWebElement autocompleteButton = (RemoteWebElement) webDriverGee
			.findElementByXPath("//div[contains(text(), \"Autocomplete\")]/..");

	if (isAutocompleChecked(autocompleteButton)) {
		// Disable the Autocomplete of special characters
		autocompleteButton.click();
	}

}