Skip to content

Conversation

@TikhomirovSergey
Copy link
Contributor

There are a lot of projects that extends Selenium Webdriver. And the returning of WebElement is not comfortable because there is the necessity to cast the result each time.

Here is the sample from Appium:

  (MobileElement) driver.findElementBy(By.class("someClass"))

In order to avoid this inconvenience these things are proposed:

  • now SearcContext and similar interfaces return the generic result insted of WebElement
  • this change is implemented by RemoteWebDriver and RemoteWebElement

It is backward compatible with current projects and it gives some more points:

  • now we can get RemoteWebElement directly
RemoteWebElement r =  driver.findElementBy(By.class("someClass"))
  • if some project contains RemoteWebElement subclasses whose objects are returned using customized JsonToWebElementConverter implementions
    then there is no need to cast the result each time.

@bootstraponline
Copy link
Contributor

👍

1 similar comment
@Jonahss
Copy link
Contributor

Jonahss commented Mar 9, 2015

👍

@andreastt andreastt added Z-awaiting review Archived: use GitHub review assignments C-java Java Bindings labels Mar 9, 2015
@barancev
Copy link
Member

Is it worth to add new tests for this feature?

@TikhomirovSergey
Copy link
Contributor Author

@barancev In order to demonstrate that the new feature is ok today I can add two new tests. They will check these cases

RemoteWebElement r =  driver.findElement(someBy);

and

List<RemoteWebElement> rList =  driver.findElements(someBy);

@jleyba
Copy link
Contributor

jleyba commented Mar 10, 2015

I'm opposed to this change as it weakens the contract on SearchContext by implying it's capable of returning specific subtypes of WebElements:

interface FooWebElement extends WebElement {
}

public static void main(String[] args) {
  SearchContext sc = new RemoteWebDriver(null);
  FooWebElement el = sc.findElement(By.id("bar"));
}

@TikhomirovSergey
Copy link
Contributor Author

@jleyba Thanks for the remark. I will try to find the way to avoid the problem that you have mentioned

@andreastt andreastt added the Z-needs code changes Archived: use GitHub review features label Mar 10, 2015
@TikhomirovSergey
Copy link
Contributor Author

Ok. I can't find the correct way to resolve the possible problem mentioned by @jleyba. So I am closing this PR. I will propose something better next time.

Thanks for the attention.

@andreastt
Copy link
Member

Thanks for the work you put into this, @TikhomirovSergey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-java Java Bindings Z-awaiting review Archived: use GitHub review assignments Z-needs code changes Archived: use GitHub review features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants