4
selenium.getDriver().findElement(By.id("s2id_customFilter")).sendKeys(Keys.ARROW_DOWN);

Am using the above code but it's not working."s2id_customFilter" is the id of the drop down.Am clicking on the id and sending keys but there's no action from selenium.

My code:

jQueryWebElement filterElement = selenium.jQuery("#s2id_customFilter");
selenium.jQuery(".select2-choice",filterElement).click();
JOptionPane.showMessageDialog(null, "one");
selenium.getDriver().findElement(By.id("s2id_customFilter")).sendKeys(Keys.ARROW‌​_DOWN);
  • 2
    Probably depends on where the focus is. If you put a call to Click() first, to make sure focus is on the drop-down list, does that make a difference? – Vince Bowdren Jun 20 '13 at 15:32
  • I agree with @vincebowdren . It sounds to me like a focus issue as well. – djangofan Jun 20 '13 at 19:59
  • @vincebowdren ... No difference it's still not working.Yes i have mentioned a click() before the above code to click on drop-down. – kittudk Jun 21 '13 at 8:06
  • 2
    @selenium_vtiger If that's the solution you used to get the job done, perhaps you could craft a small post describing that, and then accept it as your solution? That'd be greatly appreciated! – corsiKa Mar 13 '14 at 18:16
  • 1
    Ive got the same issue and reported here github.com/angular/protractor/issues/1622. – Philip Beadle Dec 11 '14 at 22:27
4

I really like the answer from the link Philip Beadle posted in a comment:

It's a bad idea to test the core browser's behaviour as it's not your logic, i.e. you should not need to test that arrow keys work with options since that's something your browser implements.

And some Protractor (JavaScript) examples how to handle the drop from the same link:

var options = element(by.id('s2id_customFilter'));
    options.sendKeys('textofyouroption')

And another one when the text changes a lot or is dynamic:

var optionsElements = element(by.id('s2id_customFilter')).all(by.tagName('option'));
    optionsElements.count().then(function(count) {
      console.log('I have ' + count + ' options')
    });
    optionsElements.get(1).click(); // click on 2nd option

You should be able to do something similar in Java.

0

I think you need to move cursor first. Did you try to use moveToElement(WebElement toElement) before clicking on it? This link may be helpful.

0

May wish to try the following (C# Selenium Dev Studio 2015 environment)

There is a drop down item on the page labelled Contact Person, I used firebug inside of Mozilla FireFox to get the absolute XPATH of this drop down item as depicted below

public static readonly string ContactPerson_DD_AXPATH = 
        "html/body/div[2]/table/tbody/tr/td[2]/table/tbody/tr/td/form/table[2]/tbody/tr[7]/td[2]/select";

Then in my C# code to cause a down arrow and enter keys functions on the drop down I code:

IWebElement contactName = driver.FindElement(By.XPath(ContactPerson_DD_AXPATH));

contactName.SendKeys(Keys.ArrowDown+Keys.Enter+Keys.Escape);

I learned somewhere that sending an Escape may help some tough key sequence actions from time to time.

0

For any rubyists, I've found 'pick first option in the dropdown' a powerful way to avoid data combinatorial testing through the UI, once you create unit and integrated tests that do that testing and explain that to the business.

As a method, e.g. selecting the first school from a test field dropdown

def select_first_school select_id
  find_by_id(select_id).send_keys :arrow_down
  find_by_id(select_id).send_keys :tab
end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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