### What happened?

When the user attempts to get a web element's location and size, the code will crash because the command is not supported in W3C mode.

This is due to the fact that unlike JWP, those commands are not supported, and W3C only allows getRect as per spec.

https://w3c.github.io/webdriver/#get-element-rect

Only JWP (not W3C) allows those two as supported commands:

https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessionsessionidelementidlocation
https://www.selenium.dev/documentation/legacy/json_wire_protocol/#sessionsessionidelementidsize

The code in Selenium 3 should have checked for W3C mode like the Python implementation does, and choose accordingly. Selenium 4 is W3C mode purely and the code should have been migrated to support only that. It is currently still using JWP commands.

This means that the Python and Java implementations are not in sync, and the Java implementation is incorrect. The `getLocation` and `getSize` code for Selenium 4 could just use the `getRect` as a function in both implementations since that's all that's available, and wrap around it to extract the relevant data.

**Java**
- Selenium 3 [here](https://github.com/SeleniumHQ/selenium/blob/selenium-3.150.0/java/client/src/org/openqa/selenium/remote/RemoteWebElement.java#L363)
- Selenium 4 [here](https://github.com/SeleniumHQ/selenium/blob/selenium-4.1.4-java/java/src/org/openqa/selenium/remote/RemoteWebElement.java#L319)

**Python**
- Selenium 3 [here](https://github.com/SeleniumHQ/selenium/blob/selenium-3.150.0/py/selenium/webdriver/remote/webelement.py#L524)
- Selenium 4 [here](https://github.com/SeleniumHQ/selenium/blob/selenium-4.1.4-python/py/selenium/webdriver/remote/webelement.py#L613)


<img width="1208" alt="Screen Shot 2022-05-25 at 13 37 53" src="https://user-images.githubusercontent.com/2030850/170560210-a8eb2adc-66f1-43fc-9773-f8ab9b8fe59d.png">
---
<img width="1197" alt="Screen Shot 2022-05-25 at 13 41 57" src="https://user-images.githubusercontent.com/2030850/170560238-3ffc55a3-2ae9-4412-b076-e3a89bee1cdf.png">

The solution for Selenium 4 Java (and similarly Python) can just be something like:

```java
@Override
@SuppressWarnings({"unchecked"})
public Point getLocation() {
  Rectangle rect = getRect();
  return rect.getPoint();
}

@Override
@SuppressWarnings({"unchecked"})
public Dimension getSize() {
  Rectangle rect = getRect();
  return rect.getDimension();
}

@Override
@SuppressWarnings({"unchecked"})
public Rectangle getRect() {
  Response response = execute(DriverCommand.GET_ELEMENT_RECT(id));
  Map<String, Object> rawRect = (Map<String, Object>) response.getValue();
  int x = ((Number) rawRect.get("x")).intValue();
  int y = ((Number) rawRect.get("y")).intValue();
  int width = ((Number) rawRect.get("width")).intValue();
  int height = ((Number) rawRect.get("height")).intValue();
  return new Rectangle(x, y, height, width);
}
```

or for consistency, this:

```java
@Override
@SuppressWarnings({"unchecked"})
public Point getLocation() {
  Response response = execute(DriverCommand.GET_ELEMENT_RECT(id));
  Map<String, Object> rawPoint = (Map<String, Object>) response.getValue();
  int x = ((Number) rawPoint.get("x")).intValue();
  int y = ((Number) rawPoint.get("y")).intValue();
  return new Point(x, y);
}

@Override
@SuppressWarnings({"unchecked"})
public Dimension getSize() {
  Response response = execute(DriverCommand.GET_ELEMENT_RECT(id));
  Map<String, Object> rawSize = (Map<String, Object>) response.getValue();
  int width = ((Number) rawSize.get("width")).intValue();
  int height = ((Number) rawSize.get("height")).intValue();
  return new Dimension(width, height);
}

@Override
@SuppressWarnings({"unchecked"})
public Rectangle getRect() {
  Response response = execute(DriverCommand.GET_ELEMENT_RECT(id));
  Map<String, Object> rawRect = (Map<String, Object>) response.getValue();
  int x = ((Number) rawRect.get("x")).intValue();
  int y = ((Number) rawRect.get("y")).intValue();
  int width = ((Number) rawRect.get("width")).intValue();
  int height = ((Number) rawRect.get("height")).intValue();
  return new Rectangle(x, y, height, width);
}
```

In Selenium 3 this was a parameterized choice of one or the other based on whether the test was run in JWP or W3C modes. in Selenium 4, those two functions are basically just helper/wrapper functions.

### How can we reproduce the issue?

Visit a webpage (Selenium) or a WebView (Appium) in W3C mode, and attempt to get the size or location of a `WebElement`.

`webElement.getLocation();`

`webElement.getSize();`

The workaround is to use the API directly as the fix above would suggest and use:

`webElement.getRect().getPoint();`

`webElement.getRect().getDimension();`

The problem with this is that a lot of teams that are using this for their testing and want to migrate already have much of their code written in the former use case. It would ease the friction of migration and save lost hours of debugging time to correct the implementation and allow teams to use their code in its existing state without the workaround.


### Relevant log output

**Description:** "Cannot call non W3C standard command while in W3C mode "

When using `getLocation()`

```shell
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:45)
at io.appium.java_client.MobileElement.execute(MobileElement.java:1)
at io.appium.java_client.android.AndroidElement.execute(AndroidElement.java:1)
at org.openqa.selenium.remote.RemoteWebElement.getLocation(RemoteWebElement.java:337)
```

--

When using `getSize()`

```shell
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:45)
at io.appium.java_client.MobileElement.execute(MobileElement.java:1)
at io.appium.java_client.android.AndroidElement.execute(AndroidElement.java:1)
at org.openqa.selenium.remote.RemoteWebElement.getSize(RemoteWebElement.java:346)
```


### Operating System

Not Applicable but on macOS against Android and iOS

### Selenium version

Java Selenium 3 and 4

### What are the browser(s) and version(s) where you see this issue?

WebView

### What are the browser driver(s) and version(s) where you see this issue?

Available on Request

### Are you using Selenium Grid?

No
}
    if (!(other instanceof RemoteWebElement)) {
      return false;
    }
    RemoteWebElement otherRemoteWebElement = (RemoteWebElement) other;
    return id.equals(otherRemoteWebElement.id);
  }
  /**
   * @return This element's hash code, which is a hash of its internal opaque ID.
   */
  @Override
  public int hashCode() {
    return id.hashCode();
  }
  /*
   * (non-Javadoc)
   *
   * @see org.openqa.selenium.internal.WrapsDriver#getWrappedDriver()
   */
  @Override
  public WebDriver getWrappedDriver() {
    return parent;
  }
  @Override
  public boolean isDisplayed() {
    Object value = execute(DriverCommand.IS_ELEMENT_DISPLAYED(id))
      .getValue();
    try {
      
      if (value == null) {