Press arrow down key 5 times usign webdriver

瀏覽次數:30,653 次
跳到第一則未讀訊息

Nagaraju

未讀,
2012年7月12日 清晨6:10:072012/7/12
收件者:seleniu...@googlegroups.com
Hi All,

I am using web driver to select a value from auto suggestion.
I want to select the 5th suggestion.

i am using

driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);
driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);
driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);
driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);
driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);
driver.findElement(By.id("sb")).sendKeys(Keys.ENTER);



But i don't want to use arrow_down 5 times..i read some where we can
pass number..Can any one help me?

Thanks,
Raju

Homewrecker

未讀,
2012年7月12日 上午8:22:112012/7/12
收件者:seleniu...@googlegroups.com
for (int i=0; i<5; i++){
driver
.findElement(By.id("sb")
).sendKeys(Keys.ARROW_DOWN);
if(i = 4){
driver
.findElement(By.id("sb"
)).sendKeys(Keys.ENTER);}}

Oscar Rieken

未讀,
2012年7月12日 上午8:27:502012/7/12
收件者:seleniu...@googlegroups.com
in ruby I would do 

5.times { driver.find_element(id: "sb").send_keys(:arrow_down) }



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.


Nagaraju

未讀,
2012年7月12日 上午8:30:102012/7/12
收件者:seleniu...@googlegroups.com
Does any one know how to do it in Java..?


On 7/12/2012 5:57 PM, Oscar Rieken wrote:
in ruby I would do 

5.times { driver.find_element(id: "sb").send_keys(:arrow_down) }

On Thu, Jul 12, 2012 at 6:10 AM, Nagaraju <nag...@gmail.com> wrote:
Hi All,

I am using web driver to select a value from auto suggestion.
I want to select the 5th suggestion.

i am using

driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);
driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);
driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);
driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);
driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);
        driver.findElement(By.id("sb")).sendKeys(Keys.ENTER);



But i don't want to use arrow_down 5 times..i read some where we can pass number..Can any one help me?

Thanks,
Raju


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

Homewrecker

未讀,
2012年7月12日 上午8:31:392012/7/12
收件者:seleniu...@googlegroups.com
The solution I posted is Java ...


On Thursday, July 12, 2012 2:30:10 PM UTC+2, Nagaraju Dasam wrote:
Does any one know how to do it in Java..?

On 7/12/2012 5:57 PM, Oscar Rieken wrote:
in ruby I would do 

5.times { driver.find_element(id: "sb").send_keys(:arrow_down) }

On Thu, Jul 12, 2012 at 6:10 AM, Nagaraju <nag...@gmail.com> wrote:
Hi All,

I am using web driver to select a value from auto suggestion.
I want to select the 5th suggestion.

i am using

driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);
driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);
driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);
driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);
driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);
        driver.findElement(By.id("sb")).sendKeys(Keys.ENTER);



But i don't want to use arrow_down 5 times..i read some where we can pass number..Can any one help me?

Thanks,
Raju


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.

Nagaraju

未讀,
2012年7月12日 上午8:34:402012/7/12
收件者:seleniu...@googlegroups.com
Homewrecker,

The solution you posted is good, but i think there is another command that i can pass number of the arrowkeys down.

driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN , 5);

i didn't remember exactly the command..for specifying the number.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/XmsayW2WX_YJ.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

Homewrecker

未讀,
2012年7月12日 上午8:40:502012/7/12
收件者:seleniu...@googlegroups.com
Looking at the javadocs, sendkeys only accepts one parameter, being a Charsequence:
void sendKeys(java.lang.CharSequence... keysToSend)

The only way to do this, afaik, is the way I posted it.

Nagaraju

未讀,
2012年7月12日 上午9:09:162012/7/12
收件者:seleniu...@googlegroups.com
Thank you very much Homewrecker.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/ZlUD3Uuj8yYJ.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

Mike Riley

未讀,
2012年7月12日 中午12:22:082012/7/12
收件者:seleniu...@googlegroups.com
A better way:
WebElement we = driver.findElement(By.id("sb"));

for (int i=0; i<5; i
++)
{
   
we.sendKeys(Keys.ARROW_DOWN);
}   // for
we.sendKeys(Keys.ENTER);

Now you aren't searching for the same element 6 times!

Mike

Karthik Kulkarni

未讀,
2012年7月12日 下午2:05:072012/7/12
收件者:seleniu...@googlegroups.com
Other method is figure out X path for the first element in the drop down . check whether there is a similar pattern . Put it in a for loop and use it

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/HkY-sU7l1jYJ.

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

Oscar Rieken

未讀,
2012年7月13日 下午1:42:412012/7/13
收件者:seleniu...@googlegroups.com
I dont know if that is a better solution, I don't want to make assumptions on what he is trying to do, what if the element with an id of "sb" is actually a path for a chart? or an image in some sort of javascript that rotates. if you just located it the first time when you tried to do the second arrow_down you could end up with a stale element reference error since there was something happening in the page and that element is not actually the same element the second go.

but yes i agree locating the element once would be better, but with limited information I can only give a limited answer. without making assumptions

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/HkY-sU7l1jYJ.

To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

Mike Riley

未讀,
2012年7月13日 下午5:58:572012/7/13
收件者:seleniu...@googlegroups.com
A valid point.  It might be going stale or changing in some way, but since there is no delay between searches I figured that wasn't the case here.

Mike

lucky lakshmi

未讀,
2013年12月11日 晚上11:44:132013/12/11
收件者:seleniu...@googlegroups.com




Keys.ARROW_DOWN is not working can any one  help me how to do it with example.

Дима Дубык

未讀,
2013年12月12日 下午4:49:032013/12/12
收件者:seleniu...@googlegroups.com


Четвер, 12 липня 2012 р. 13:10:07 UTC+3 користувач Nagaraju Dasam написав:



You can try driver.findElement(By.id("sb").findElement(By.xpath("(//table[@class='demo_table']//tr)[4]").Click();

<table class="demo_table">
    <tbody>
        <tr class="">
        <tr class="">
        <tr class="">
        <tr class="">

radhe.p...@gmail.com

未讀,
2014年10月9日 凌晨4:50:192014/10/9
收件者:seleniu...@googlegroups.com

How to  move course to context menu?
I have write below code but it is not working

action.contextClick(driver.findElement(By.xpath(proc.getProperty("FilterItem")))).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).
sendKeys(Keys.ARROW_RIGHT).sendKeys(Keys.ARROW_DOWN).perform();

Vishal Jalgaonkar

未讀,
2015年5月19日 上午11:53:162015/5/19
收件者:seleniu...@googlegroups.com
You can try below :

//First Locate the "Select" options element by name or id
WebElement elem = driver.findElement(By.name("ctl00$phBody$ddlCancelType")); 

//Use Actions api to click on Options
builder = new Actions(driver);
builder.click(elem);
selectMultiple = builder.build();
selectMultiple.perform(); 

//Select 2nd Option
Robot robot = new Robot(); 
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyPress(KeyEvent.VK_PAGE_DOWN); 

Brian Smith

未讀,
2015年5月20日 晚上9:17:422015/5/20
收件者:seleniu...@googlegroups.com
Post a snippet of the DOM containing the element with all the autocomplete options, and I can easily assist you.

CH!NN@ K

未讀,
2015年5月21日 凌晨1:03:082015/5/21
收件者:seleniu...@googlegroups.com
Hi Refer this below link for Keyboard action(like ARROW_DOWN, ARROW_UP  ) using Selenium Webdriver.
http://www.techlearn.in/content/how-handle-auto-suggestion-using-selenium-webdriver

---
Thanks & Regards,
Purushotham Karimbedu,
Drupal Developer and QA Engineer,
Website for Selenium : http://techlearn.in


On Thu, May 21, 2015 at 6:47 AM, Brian Smith <crazyc...@gmail.com> wrote:
Post a snippet of the DOM containing the element with all the autocomplete options, and I can easily assist you.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/4eb397e7-6b0a-47a3-bb5b-f02884ea83c1%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Mercious

未讀,
2015年5月21日 清晨7:47:082015/5/21
收件者:seleniu...@googlegroups.com、incubu...@gmail.com
Just as reference, if ( i == 4 ) not ( i = 4). The latter one is always true.

Just incase someone copy pastes this and is getting errors because of this simple typo.

Shawn Knight

未讀,
2015年5月24日 上午9:36:162015/5/24
收件者:seleniu...@googlegroups.com
Using Java 8 ....
IntStream.iterate(1, n -> n + 1).limit(4).forEach(number -> driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN));
driver.findElement(By.id("sb")).sendKeys(Keys.ENTER)

Bharti Mahani

未讀,
2016年7月10日 上午9:03:272016/7/10
收件者:Selenium Users
Hi, 
Does 
driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN); means the control is now on the next element after "SB"??

If I have to read next element after element "sb' what would be the code?

Thanks,
Bharti

Purushotham Karimbedu

未讀,
2016年7月10日 上午9:45:122016/7/10
收件者:seleniu...@googlegroups.com

---
Thanks & Regards,
Purushotham Karimbedu,
Drupal Developer and QA Engineer,
Phone no: 09000109120.


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Bharti Mahani

未讀,
2016年7月10日 上午10:28:402016/7/10
收件者:seleniu...@googlegroups.com
I did like

  WebElement element=driver.findElement(By.id("menubtn-live-tv"));
        for (int i=0;i<9;i++)
        {
            element.sendKeys(Keys.ARROW_DOWN);
        }
element.sendKeys(Keys.ENTER);
First query:  I get following exception.

Second query: But incase focus is found, how to read next object's class attribute, (if ARROW_DOWN takes to the next object according to you.)


org.openqa.selenium.WebDriverException: unknown error: cannot focus element
  (Session info: chrome=51.0.2704.103)
  (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 58 milliseconds
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'INDXBC261', ip: '10.10.9.192', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_91'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, chrome={userDataDir=C:\Users\Bharti_M\AppData\Local\Temp\scoped_dir4248_12494}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=51.0.2704.103, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: a0ee682550d383803e0b895678d5197f
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327)
    at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:122)
    at com.stb.scenarioDefinition.WatchListVerification.we_are_able_to_focus_to_objects(WatchListVerification.java:55)
    at ✽.Then We are able to focus to objects(stb.feature:9)



--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/0hOGu5La1nQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

Bharti Mahani

未讀,
2016年7月10日 上午11:05:012016/7/10
收件者:seleniu...@googlegroups.com
This exception is not coming on firefox. Now another query
Can I do  driver.findElement(By.id("menubtn-live-tv")).sendKeys(Keys.ARROW_DOWN).getText();

I want to fetch the next element text.

--

Anthony C

未讀,
2016年7月20日 晚上10:30:562016/7/20
收件者:Selenium Users
I used this with Selenium Webdriver and Java and it works

driver.findElement(By.id("sb")).sendKeys(Keys.ARROW_DOWN);

Anthony Caramagno

未讀,
2016年7月20日 晚上10:47:402016/7/20
收件者:seleniu...@googlegroups.com
There is a way to pass an index number of the items in a dropdown. No down arrow involved. Is that ok?

Thanks, 

-Anthony
(Sent via mobile device)
--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/0hOGu5La1nQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Sekhar Jasty

未讀,
2016年7月21日 凌晨3:03:562016/7/21
收件者:seleniu...@googlegroups.com
I guess this is what you are looking for. 

Select dname = new Select(driver.findElement(By.id("selenium_commands")));
 
dname.selectByVisibleText("Wait Commands");
Wait Commands is the autosuggestion value and it could be 5th or 4th or 1st value.  



Thanks,
Jasty

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.
回覆所有人
回覆作者
轉寄
0 則新訊息