driver.findElement(By.cssSelector("#opGata")).sendKeys("Rinkeby");driver.findElement(By.cssSelector("#opGata")).sendKeys("R");
driver.findElement(By.cssSelector("#opGata")).sendKeys(Keys.DOWN);
driver.findElement(By.cssSelector("#opGata")).sendKeys("i");
driver.findElement(By.cssSelector("#opGata")).sendKeys(Keys.DOWN);
driver.findElement(By.cssSelector("#opGata")).sendKeys("n");
driver.findElement(By.cssSelector("#opGata")).sendKeys(Keys.DOWN);
driver.findElement(By.cssSelector("#opGata")).sendKeys("k");
driver.findElement(By.cssSelector("#opGata")).sendKeys(Keys.DOWN);
driver.findElement(By.cssSelector("#opGata")).sendKeys("e");
driver.findElement(By.cssSelector("#opGata")).sendKeys(Keys.DOWN);
driver.findElement(By.cssSelector("#opGata")).sendKeys("b");
driver.findElement(By.cssSelector("#opGata")).sendKeys(Keys.DOWN);
driver.findElement(By.cssSelector("#opGata")).sendKeys("y");
driver.findElement(By.cssSelector("#opGata")).sendKeys(Keys.DOWN);
Keys.DOWN is a synonym for Keys.ARROW_DOWN (likewise UP, LEFT, and RIGHT), which is most likely not what you want. An individual-character call to sendKeys() ought to trigger the sending of a single keystroke, as I understand the WebElement interface. Of course, the code you’ve written types them as fast as it can, so maybe you’re not allowing the autocomplete the time it needs to trigger.
Ross
driver.findElement(By.cssSelector("#opGata")).sendKeys("Rinkeby");
driver.findElement(By.cssSelector("#opGata")).sendKeys(Keys.DOWN);
That code will do exactly what it says: type the keystrokes “R”, “i”, “n”, “k”, “e”, “b”, “y”, down_arrrow as fast as it can. If your application responds to that” by displaying a list of choices for “Rinkeby” and selecting the topmost item, then yes, that will do what you want.
There is no standard way to trigger an auto-complete list, because there is no standard auto-complete list (unless you’re talking about HTML5’s “autocomplete=’on’” attribute). If it works, use it, if not, you’ll need to figure out what works for whatever auto-complete JavaScript library your application is using.
Ross
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of mahadi
Sent: Friday, September 14, 2012 4:09 AM
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] help required on autocomplete list by sendkeys
Thanks every body for valuable suggestions.
@PeterJef: I am so sorry that your suggestion was working fine, it was not working at that time because of a bug at that time in our test environment :). Finally i managed to make it workable simply with the bellow two lines of code:
The sendKeys() method will “press” and “release” each of the keys specified, in order. If you want to combine multiple keypresses, I think you have to use the Actions interface for that (although I don’t really know how that works). I believe you can use that for things like CTRL+<some key>, etc.
Nice to see Mahadi’s separate post indicating the sendKeys(“Ringeby”) was indeed the correct answer, and that there was a non-Selenium problem that prevented it from working at first J
Ross
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Peter Gale
Sent: Thursday, September 13, 2012 4:49 PM
To: Selenium Users
Subject: RE: [selenium-users] help required on autocomplete list by sendkeys
Thanks, Ross.
The sendKeys() method will “press” and “release” each of the keys specified, in order. If you want to combine multiple keypresses, I think you have to use the Actions interface for that (although I don’t really know how that works). I believe you can use that for things like CTRL+<some key>, etc.
Nice to see Mahadi’s separate post indicating the sendKeys(“Ringeby”) was indeed the correct answer, and that there was a non-Selenium problem that prevented it from working at first J
Ross
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Peter Gale
Sent: Thursday, September 13, 2012 4:49 PM
To: Selenium Users
Subject: RE: [selenium-users] help required on autocomplete list by sendkeys
Thanks, Ross.
Yes I meant to recommend sending a sequence which registers with the browser as the action of pressing any key down, or releasing it, not sending an up/down arrow.
I can't see anything under the KEYS class that does that.
Unless anyone can suggest otherwise, initiating the event via javascript might be the best option.