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

Interacting with select controls #55

Closed
idevai opened this issue Nov 2, 2017 · 7 comments
Closed

Interacting with select controls #55

idevai opened this issue Nov 2, 2017 · 7 comments

Comments

@idevai
Copy link

idevai commented Nov 2, 2017

What's the officially recommended way of doing this? I'd like to select a particular value from a HTML select element. As first try I could do this with first clicking the select and the clicking the option, however, my controls are not working the same way when it happens with human interaction (seemingly some javascript events are not fired properly?!)

@komcrad
Copy link

komcrad commented Nov 2, 2017

I'd look at the Select object in selenium and see how they handle it. I think it's part of the webdriver protocol. I don't believe they use any javascript shenanigans to accomplish the task.

You probably don't have a strong need to emulate human interaction perfectly. Otherwise, you'd be testing the functionality of a select element. I don't think that's necessary.

@idevai
Copy link
Author

idevai commented Nov 2, 2017

I've looked into their sources, what they do is simply a click on the option (without first clicking the select). I've modified my test, but it's still the same. What I also observe is that seemingly the onClick handler gets called, but not the onInput. With human interaction in the browser, both onClick and onInput gets called.

@komcrad
Copy link

komcrad commented Nov 3, 2017

I don't think it's a bad option. Once again, you are probably wanting to not test the html elment itself.

@idevai
Copy link
Author

idevai commented Nov 3, 2017

Ah found the issue. Actually onInput is not valid in case of a select element, only for input type of elements. Changing to the onChange event works both for Webdriver and human interaction. Thank you.

@idevai idevai closed this as completed Nov 3, 2017
@igrishaev
Copy link
Collaborator

@idevai well, it depends on what HTML structure do you have.

Sometimes, select widgets are implemented manually with lots of nested divs. In that case, you need to click on select, wait for a short time, then click on an element appeared in dropdown next.

When dealing with native select fields, you may send them proper keys. The standard (fill...) function should work. Most of modern browsers select proper option when you type something focusing on the main select field. Or you may click on select, wait for a bit and then click on <option> element.

@rgscherf
Copy link

rgscherf commented Feb 1, 2018

@igrishaev Both (click...) and (fill...) work great for selecting single elements. Is there a way to select more than one at a time, though? E.g. as if ctrl-clicking another element?

edit -- looks like this functionality would be part of #103?

@igrishaev
Copy link
Collaborator

@rgscherf right. Currently, I'm looking through actions in the Webdriver spec. Once I add them, there might be some high-level wrappers for custom action combos.

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

4 participants