0

I am trying to enter a value in an input box and immediately hit enter to trigger a function via Selenium Webdriver & ruby. The problem is the value is reflected into input filed but the enter event is not triggered.

Below is my code for same:

elements = browser.find_elements(:css,".formProperty.fpMandatory.fpUpdateable .off .collapsedView.Uncompleted .fpColValue .textFieldValueSelector.valueSelector  .integer")

elements[0].send_keys"5"

elements[1].send_keys"5"

elements[2].send_keys"2"

elements[2].send_keys(:enter)

Any work around please?

Thanks, Abhishek

2 Answers2

2

Send :return instead of enter:. This answer talks about the difference.

Community
  • 1
  • 1
JaneGoodall
  • 1,478
  • 2
  • 15
  • 22
  • I suspect one is a carriage return[1] and the other is a new line since they map to different keys[2]. 1) http://en.wikipedia.org/wiki/Enter_key#Differences_between_Enter_and_Return 2) http://rubydoc.info/gems/selenium-webdriver/0.2.0/Selenium/WebDriver/Keys – JaneGoodall Apr 07 '14 at 22:39
1

I think this will work for you:

elements[2].send_keys"2", :enter

Second suggestion:

elements[2].send_keys"2"
browser.action.click(elements[2]).send_keys(:enter).perform
Richard
  • 8,961
  • 3
  • 38
  • 47
  • Didn't help :( Same effect, only text is pushed into the field but no enter event. – SoftwareTestingEnthusiast Apr 07 '14 at 21:58
  • @user007 Have you verified that manually pressing enter in the web page has the effect you expect? Also, is there a button you can click instead? – Richard Apr 07 '14 at 22:00
  • Yes, manually hitting the enter key while the cursor is still in the textbox triggers the function as expected. Theres no button where it could be clicked. Main objective is by hitting enter key another collapsed tile expands and the focus is directed into new text field. But I am unable to detect this expandable section too :( – SoftwareTestingEnthusiast Apr 07 '14 at 22:05
  • I was able to expand the tile with the help of xpath but that only helps in filling up of text fields. It requires enter key event to trigger the function at all costs. So I tried your solution as follows: `#Rental Cars cars = browser.find_element(:xpath,"/html/body/div[5]/div/div[3]/div[2]/div[2]/div/div/div/div/div[2]/div[2]/div/div/div/div[2]/div/div/div[5]/div/div[2]/div[2]/div/div/div/div[3]/div/div/div[3]/div/div/input") browser.action.click(cars).send_keys(:enter).perform` That didnt help too. – SoftwareTestingEnthusiast Apr 07 '14 at 22:40
  • if we specify same xpath and append return, then it triggers the function. – SoftwareTestingEnthusiast Apr 07 '14 at 22:54