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

Select option without value #299

Open
tp6g04jp6 opened this issue Jul 12, 2017 · 7 comments
Open

Select option without value #299

tp6g04jp6 opened this issue Jul 12, 2017 · 7 comments

Comments

@tp6g04jp6
Copy link

tp6g04jp6 commented Jul 12, 2017

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>
@yurydyatlov
Copy link

No answer? Also need help with this.

@awlayton
Copy link
Collaborator

awlayton commented Sep 5, 2017

Doesn't this work?

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

@yurydyatlov
Copy link

Could not succeed. Can i select by index?

@awlayton
Copy link
Collaborator

awlayton commented Sep 5, 2017

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);
});

@yurydyatlov
Copy link

yurydyatlov commented Sep 5, 2017

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?

@awlayton
Copy link
Collaborator

awlayton commented Sep 5, 2017

You should be able to just click on it then.

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

@yurydyatlov
Copy link

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

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

No branches or pull requests

3 participants