Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

Which Selenium Webdriver command is used for selecting items from combobox in Java?

I mean when we want to select one item from a Combobox but this element is not an instance of Select class, e.g., element found by commands like this

driver.findElement(By.id(elementId))
share|improve this question
3  
Google for: select combobox selenium –  dzieciou Oct 25 '13 at 14:01
    
@dzieciou Did you actually google it? It takes you to a stack overflow post. Just because something is simple doesn't mean it isn't of value. The only thing I see wrong with the post is that it isn't immediately clear what the user's prior effort in solving the problem is, although I suspect that's what the last sentence is for. –  corsiKa Oct 28 '13 at 13:26
    
@corsiKa, yes, I googled for it and it took me to the stackoverflow.com/questions/6924550/… post that answers the question, i.e., it "select one item from Combobox" that "is not select". I've never said simple questions aren't valueable, I just demonstrated a way to find an answer. If you want to discuss "How much prior research effort is expected before asking a question?" we could talk about this on meta. We could also discuss there whether we want to duplicate questions from other SE sites. –  dzieciou Oct 28 '13 at 15:50
    
@user6261, I updated your question trying to clarify it. Is this what you meant? –  dzieciou Oct 28 '13 at 16:43

1 Answer 1

You need to create a Select element instead of a simple WebElement.

Select selectObject = new Select(driver.findElement(By.id(elementId)));
selectObject.selectByValue("Item1"); // Assuming you have an element with value Item1 in your combo box
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.