Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CSS selector matcher #211

Open
bootstraponline opened this issue Aug 8, 2016 · 11 comments
Open

Add CSS selector matcher #211

bootstraponline opened this issue Aug 8, 2016 · 11 comments

Comments

@bootstraponline
Copy link
Contributor

bootstraponline commented Aug 8, 2016

Given the following input:

Matching on title or value will fail.

$x('//input[@title="Email" or @value="Email"]')
> []

Place holder matching works but it's not unique.

$x('//input[@title="Email" or @value="Email" or @placeholder="Email"]')
> [<input class=​"ic-Input" type=​"text" name=​"pseudonym_session[unique_id]​" value placeholder=​"Email">​, 
   <input class=​"ic-Input" type=​"text" name=​"pseudonym_session[unique_id_forgot]​" value placeholder=​"Email" id=​"pseudonym_session_unique_id_forgot">​]

I think we need to allow matching on arbitrary XPath selectors since there's no way to control the content of the webview.

@bootstraponline
Copy link
Contributor Author

In Espresso, I can login via arbitrary CSS selectors or XPath.

// Espresso
String EMAIL = "input[type=\"email\"]";
String PASSWORD = "input[type=\"password\"]";

onWebView()
  .withElement(findElement(Locator.CSS_SELECTOR, EMAIL))
  .perform(webKeys("some email"))
  .withElement(findElement(Locator.CSS_SELECTOR, PASSWORD))
  .perform(webKeys("password"))

@bootstraponline
Copy link
Contributor Author

https://gist.github.com/tirodkar/cf4a72d98264545749b063e79838fa03 looks like a good work around until the new webview APIs are ready.

@khandpur
Copy link
Collaborator

Would adding a css selector as a matcher address this issue? If so, we could rephrase this to sound like a feature request and add the example above as a test for the feature.

@bootstraponline
Copy link
Contributor Author

Would adding a css selector as a matcher address this issue?

Yes.

@bootstraponline bootstraponline changed the title grey_webSetText fails when there's no title or value Add CSS selector matcher Aug 23, 2016
@bootstraponline
Copy link
Contributor Author

bootstraponline commented Mar 27, 2017

some notes since I've started looking into this:

Espresso serializes HTML elements to a JSON ElementReference

That looks like:

{"ELEMENT":":wdc:1490646488594"}

which is standard WebDriver.

I haven't yet figured out how to create references from a located HTML element although the following code looks promising.

@bootstraponline
Copy link
Contributor Author

bootstraponline commented Mar 29, 2017

Here's the code for my port of Espresso's WebView logic to Swift & EarlGrey.

css_selector_victory

It's very much a proof of concept with most of the APIs not yet implemented. The approach is verified as working though.

@bootstraponline
Copy link
Contributor Author

bootstraponline commented Apr 3, 2017

I pushed an update which adds element reference support & webKeys (typing text).

Example usage:

private let EMAIL_FIELD_CSS = "input[name=\"email\"]";
if let emailElement = DriverAtoms.findElement(locator: Locator.CSS_SELECTOR, value: EMAIL_FIELD_CSS) {
  DriverAtoms.webKeys(element: emailElement, value: "[email protected]")
}

@drzajwo
Copy link

drzajwo commented Feb 21, 2019

I pushed an update which adds element reference support & webKeys (typing text).

Example usage:

private let EMAIL_FIELD_CSS = "input[name=\"email\"]";
if let emailElement = DriverAtoms.findElement(locator: Locator.CSS_SELECTOR, value: EMAIL_FIELD_CSS) {
  DriverAtoms.webKeys(element: emailElement, value: "[email protected]")
}

As we spoke on Slack, could you please update the links? Maybe I'll try to implement your solution which seems to be very interesting ;)

@bootstraponline
Copy link
Contributor Author

@tirodkar
Copy link
Collaborator

Do you have a matcher we could add in EG 2 as well? @bootstraponline

@bootstraponline
Copy link
Contributor Author

I completed the experimental prototype for EarlGrey 1. I'm not sure if it works for EG2. I expect it'd need some stabilization before being mainlined. XCUITest solved the simple webview use case I cared about.

I think a larger project to port espresso web for real to EarlGrey would be nice.

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

No branches or pull requests

4 participants