johntitus/node-horseman

Select option without value

tp6g04jp6 opened this issue · 7 comments

How to select an option without value?

For example:
HTML:

<select name="main_road" id="main_road" onchange="mainRoadChange();">
    <option>A</option>
    <option>B</option>
    <option>C</option>
</select>

No answer? Also need help with this.

Doesn't this work?

horseman.select('#main_road', 'A') // Select first option

Could not succeed. Can i select by index?

No you cannot select by index.

It is weird to me that the option tags do not have a value. The default for value is supposed to be the text inside the option tag. If that does not work, I do not know how to select it short of something like:

horseman.evaluate(function() {
  // Select first option
  $('#main_road :nth-child(1)').prop('selected', true);
});

First of all thank you for your help. I tried your code and it should work, but i realised that not in my case, in website i'm crawling i think where is onclick event when selecting (That is why there is no value in option). So i should simulate click on option. Any chance to do this?

You should be able to just click on it then.

horseman.click('#main_road :nth-child(1)')

Didn't work. Should i open/click Select element before click?