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

Documentation on By.js is Incorrect #7251

Closed
machineghost opened this issue May 30, 2019 · 1 comment
Closed

Documentation on By.js is Incorrect #7251

machineghost opened this issue May 30, 2019 · 1 comment

Comments

@machineghost
Copy link

machineghost commented May 30, 2019

🐛 Bug Report

In Javascript an expression (eg. 1 + 1) and a statement (eg. const a = 1 + 1; or return a;) are different things, but the documentation for By.js refers to it requiring an "expression" when it actually requires a statement (specifically a return statement).

To Reproduce

  1. Go to https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/by_exports_By.html#By.js
  2. Try to follow the instructions: provide a "a JavaScript expression"
  3. Receive a (difficult to debug) TypeError: Custom locator did not return a WebElement
  4. Change the "Javascript expression" to instead be the statement of: return *whatever expression you had before*
  5. Get your expected element

Expected behavior

The documentation should be changed from:

Locates an elements by evaluating a JavaScript expression. The result of this expression must be an element or list of elements.

to:

Locates elements by evaluating a JavaScript return statement. The value returned from this statement must be an element or list of elements.

Example:
driver.findElement({ js: "return document.querySelectorAll('button')" }))

Arguably a much better solution would be to make this function actually expect an expression. There's really no reason to make devs provide:

return document.querySelector('foo')`

when they could just provide:

`document.querySelector('foo')`

... but I'm guessing it's easier to avoid breaking things by just fixing the documentation :)

OS: Any
Browser:Any
Browser version: Any
Browser Driver version: Current (documentation for version at https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/by_exports_By.html#By.js)
Language Bindings version: Javascript
Selenium Grid version (if applicable): n/a

@jleyba jleyba closed this as completed in 117b05b Jun 5, 2019
@machineghost
Copy link
Author

Thanks!

@lock lock bot locked and limited conversation to collaborators Aug 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant