Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow Browser.select() to select by option textContent #260

Closed
nauhygon opened this Issue · 3 comments

2 participants

@nauhygon

Currently Browser.select() allows to select an option by value or label. It would make a Zombie lover's life like mine much easier to also allow to choose an option based on its textContent because that's what I see and I don't have to look hard at the values and labels embedded in the page source.

For example, I would like to

var browser = new Browser();
browser.visit(url, function() {
    browser.select("month", "Jan 2011");
});

from

<html>
    <body>
      <select id="month" name="month">
        <option value="10">Jan 2011</option>
        <option value="11">Feb 2011</option>
        <option value="12">Mar 2011</option>
      </select>
    </body>
</html>

While we are at it, maybe also a good idea to strip leading/trailing spaces of the textContent.

@assaf
Owner

It already does. I think you're confusing the notion of a label (some controls like options have labels) and specific elements/attributes with that name.

@nauhygon

Thanks for the response. That's what I thought as well. I should have posted the test I did.

var Browser = require("zombie");

browser = new Browser({debug: true});

browser.visit("file://"+__dirname+"/select.html", function() {
    console.log(browser.html("#month"));
    browser.select("#month", "Jan 2011");
});

The html the above code loads is

<html>
  <body>
    <select id="month" name="month">
      <option value=""></option>
      <option value="10">Jan 2011</option>
      <option value="11">Feb 2011</option>
      <option value="12">Mar 2011</option>
    </select>
  </body>
</html>

What I got was the following error, which seems to indicate the option by its text cannot be found. No problem if I used the values to select.

Error: No OPTION 'Jan 2011'
    at Browser._findOption (/tmp/select/node_modules/zombie/lib/zombie/browser.coffee:513:15)
    at Browser.select (/tmp/select/node_modules/zombie/lib/zombie/browser.coffee:533:21)
    at /tmp/select/select.js:6:13
    at /tmp/select/node_modules/zombie/lib/zombie/browser.coffee:335:20
    at /tmp/select/node_modules/zombie/lib/zombie/browser.coffee:200:30
    at Array.0 (/tmp/select/node_modules/zombie/lib/zombie/eventloop.coffee:160:18)
    at EventEmitter._tickCallback (node.js:192:40)

I attempted to make a fix in Browser._findOption() to make use of the option element's contentText. See the change here. As I'm just starting using coffeescript and haven't spent enough time on the Zombie code, I am not sure if this is the best way to go.

Hopefully this explains why I filed this, which I think is rather a feature request than an issue.

@nauhygon nauhygon referenced this issue from a commit in nauhygon/zombie
nauhygon Add test cases for issues #241 and #260. 27c44b0
@assaf
Owner

In master

@assaf assaf closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.