SendKeys(Keys.Enter) not working in Appium - java

I have entered text in a text box. And now I want to press Enter key. To do that, I am passing sendKey(Keys.Enter) which just cut the text from the text box and does nothing.
driver.findMobileElement("id", setLocationTextBoxId).sendKeys(parkingLocation+"\n");
driver.getKeyboard().sendKeys(Keys.ENTER);
Note: "\n" is not working already. sendKeyEvent/pressKeyEvent method is not available.

To press ENTER key on Android device, you need to use Android KeyEvent codes. The key code for ENTER is 66. You can use the below code snippet.
driver.longPressKeyCode(66);
To get the all Android KeyEvent codes please refer this official link

Try this! I have the same problem like you, and i got frustated untill i found this. Hope this will help you out!
public void pressEnterEditText(String elementName, String value) {
AndroidElement tempElement = getAndroidElement(elementName);
tempElement.click();
driver.pressKey(new KeyEvent(AndroidKey.ENTER));
}

Related

Getting Text from TextField in CodeName One for Java

I have designed the GUI elements and put everything together using CodeName One plugin for Netbeans 8.1. I am first working on my client information GUI that has textfields and a submit button. I'm looking to retrieve the textfield imputs via the submit button action event(I will use the first name textfield as an example:
#Override
protected void onAddRecordGUI_SubmitButtonAction(Component c, ActionEvent event) {
..I tried this
String Fname = findTxt_Firstn(c).getText();
..I also tried this
String FirstName = findTxt_Firstn.getText();
..I then tried this
String FirstName = Txt_Firstn.getText();
}
I get "error: cannot find symbol" with regards to the textfields name (It is correct and located on the same form the button is located)
Am I doing something very wrong here? I found two post on Stack, however, I tried the solutions above anyway.
Okay! I have solved my own questions and this might be applicable to anyone else who encounters this issue. The issue isn't the code, but it is naming textfields with an underscore "_". I renamed the field and was able to create a reference to it.
Thanks.

xpath in firebug works however sendkey is not sending value

I am trying to write a login code for hotmail. I asked this a few days ago on how to get the xpath, someone answered and gave me the correct xpath in his reply:
//*[#id='CredentialsInputPane']//div[3]//div[2]/div
His answer worked.
Today I tried to come up with my own xpath solution and in Firepath when I use the following syntax it highlights the user name field.
//div[contains(#class,'placeholder has-focus')][text()='Email, phone, or Skype name']
Question/problem: When I run the test, in UI it does not send the value user#msn.com, it clicks the Next button and I get error "Please enter a value".
What is wrong with my xpath syntax, even though it is highlighting the field? Why is it not sending the email id?
Code:
driver.get("https://login.live.com/login.srf?");
driver.findElement(By.xpath("//div[contains(#class,'placeholder')][text()='Email, phone, or Skype name']")).sendKeys("usertest81#msn.com");
driver.findElement(By.xpath("//input[contains(#id,'idSIButton9')]")).click();
Thanks in advance for your time and explanation.
You are trying to send value to a non-input field. This may be the reason. Try with the following-
driver.findElement(By.name("loginfmt")).sendKeys("usertest81#msn.com");

How to copy a text from java code in cygwin?

I need to get the value of selected item and to copy it from Java application in cygwin.
My problem is that I don't know how to copy a text from Java application in cygwin.
This is a portion of my code:
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
String cmmd = "moshell"+jComboBox1.getSelectedItem()
/*I need a help here :how to write this text (cmmd) in cygwin?*/
}
I'm debutant in programming. Can someone help me to resolve this problem. Thank you.
If I understand your question, the same way you write any text to the console,
// I need a help here :how to write this text (cmmd) in cygwin?
String cmmd = "moshell"+jComboBox1.getSelectedItem();
System.out.println(cmmd);

FriendPickerSample doesn't show my friends

I am testing this sample from the Facebook SDK, but don't appear any friends... it says: " "
When I click Pick Friends, a pop up window shows:
" FriendPickerSample would like to access your public profile and friend list"
And I click "OK", but nothing happens it keeps showing only the string ""
Do you guys have any clue?
Problem solved, I didn't had the key hash registed on facebook app developer, neither had the app_id on the strings xml file.
Thanks all anyways

sendKeys.RETURN not working in FirefoxDriver

if I execute the following code in FireFoxDriver:
WebElement element = driver.findElements(By.id("some_id")); // element being a textbox
element.sendKeys("apple");
element.sendKeys(Keys.RETURN);
The sendKeys(Keys.RETURN) is not performing its desired function.
Actually what I am trying to do is Input a text in a dynamic text search box (like one in facebook search) and press enter. The input is working fine but not the enter key.
sendKeys("apple") works, even sendKeys(Keys.BACK_SPACE) works, but not Keys.RETURN.
Does anyone have ideas? Thanks guys!
Not exactly sure why this happens, but there are a couple alternate ways of doing this that may help:
If elements are in a form, and there is no javascript that runs on submit or something you can use .submit() on any form input element, such as inputs and textareas:
WebElement element = driver.findElements(By.id("some_id"));
element.sendKeys("apple");
element.submit()
You can send the newline character with your input:
WebElement element = driver.findElements(By.id("some_id"));
element.sendKeys("apple\n");
Provide send_keys a list:
WebElement element = driver.findElements(By.id("some_id"));
element.sendKeys("apple", Keys.ENTER);
Got the solution to the above problem. U just need to add, a delay.
This happens because the Java Class runs too fast, so if u have sent a call, and pressed enter/ tab, before the element arrives, the enter is pressed, that is why this doesn't work. Just add Thread.delay(1000); before your Keys.RETURN command. That will do.
Worked for me.
I tried sending \n and fiddled with various commands until I found someone explaining that "keyPress (target) 13" will send the return key.
So first I use type to enter the string I want ...
*
*<tr>
<td>type</td>
<td>id=status</td>
<td>This is my test string</td>
</tr>*
*
... and then send the Enter key to the same text input box
*
*<tr>
<td>keyPress</td>
<td>id=status</td>
<td>13</td>
</tr>*
*

Categories