appium之hideKeyboard
来源:互联网 发布:迈克尔.凯恩 知乎 编辑:程序博客网 时间:2024/05/16 08:33
Based on some digging around, it appears the keyboard's "Hide keyboard" button (even on an iphone) is located in UIAutomation at
keyboard().buttons()["Hide keyboard"].tap();
So, I did the following in python and it worked:
self.driver.execute_script('UIATarget.localTarget().frontMostApp().keyboard().buttons()["Hide keyboard"].tap();');
we should create a special mobile command for hiding the keyboard, I want to keep people from having to learn any UIAutomation for using Appium.
I propose (e.g. in Python):
self.driver.execute_script("mobile: hideKeyboard")
Will build it and update this issue when it's merged.
excellent!
And how do I do this in Java (Selenium Webdriver)? Because I'm not using Python. Thanks for the help!
I think this will help, but I'm not familiar with the Java bindings:
http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions#Q:_How_do_I_execute_Javascript_directly?
Either way, you need the Selenium WebDriver execute script command, whatever it is bound to in java.
hideKeyboard method #185
Ok, this will work now as described above! (But using the Java-appropriate method of course)
I've added some Java examples on how to execute the script commands to the https://github.com/appium/appium/wiki/Automating-mobile-gestures page
I've grabbed the latest version of appium and tried the following:
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("mobile: hideKeyboard");
The following exception appears:
org.openqa.selenium.WebDriverException: Not implemented in this context, try switching into or out of a web view
Anyone got some suggestions for me?
@jlipps I'm also getting the following error when using the latest appium and executing the 'mobile: hideKeyboard' command:
org.openqa.selenium.NoSuchElementException: Could not find the 'Hide keyboard' button, you're on your own for closing it!
@jlipps @rossrowe @raftheunis87 Can we move this to a new issue or reopen? This doesn't seem to be re-opening of its own volition.
@rossrowe Does this happen on both iPad and iPhone? Are you using an English-language device (the button find is by AXTitle, so I'm not sure if it works if using localized systems) Also, can you try using the original applescript?
self.driver.execute_script('UIATarget.localTarget().frontMostApp().keyboard().buttons()["Hide keyboard"].tap();');
I get the NoSuchElementException when I try to run the hide keyboard command using the iPhone simulator (6.0) and an English keyboard. I'll try to setup my environment to use the ipad simulator to see if the command works.
When I try the original applescript, I get the following error:
org.openqa.selenium.WebDriverException: Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().keyboard().buttons()["Hide keyboard"]
Command duration or timeout: 1.31 seconds
Build info: version: '2.29.1', revision: 'dfb1306b85be4934d23c123122e06e602a15e446', time: '2013-01-22 12:58:05'
System info: os.name: 'Mac OS X', os.arch: 'amd64', os.version: '10.8.2', java.version: '1.7.0_04-ea'
Session ID: 881e7d8a-54dd-4295-88f9-135263bcb008
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{platform=MAC, databaseEnabled=false, javascriptEnabled=true, browserName=iOS, webStorageEnabled=false, locationContextEnabled=false, takesScreenshot=true, version=6.0}]
Definitely sounds like the keyboard element isn't on that particular keyboard. What kind of input are you using? I.e. is it displaying the full text keyboard or one of the specialty keyboards, such at numeric, etc.?
On the full text keyboard, there's usually a Hide Keyboard button which is hidden, but active, which is how this mechanism works. I haven't tried it with other keyboards, so it may not be possible there, the button may have a different name, or there may be another issue.
I just added the code to the SimpleTest class to hide the keyboard that is displayed after the text fields are populated, and I'm not changing the keyboard from what appears. I've committed the code that shows what I've tried to rossrowe@11314f6
On the iPhone, I think you're really going to have to push the button in the lower-right corner of the keyboard. That's basically going to require knowing what that button is and pushing it by name. In many cases, that's "Done" or "Search".
In the case of the TestApp, it's Done. It is accessible as a button in the root window.
We may be able to find another solution to this in the future using another bit of custom javascript, but for the time being, we're limited to what we know about interaction with the keyboard.
In other words: there will be no quick solution for this problem?
I'm currently working on a POC (proof of concept) of Appium for my company, so I need to know if this will be fixed soon.
Thanks again for the quick replies guys!
@raftheunis87 The solution at the moment is to do the same thing a user would do. Tap the button that will remove the keyboard from the screen, which is going to be in the lower-right corner of the keyboard. You should be able to locate it by the text string, which is exactly what we did with the iPad version.
You should be able to do that with the above execute_script command (see java examples previously in this thread if you don't know how to call this from java) and replace the name of your "Done", "Search", whatever button for the "Hide Keyboard" button in the example code. So, using python and a "Done" button, you'll get:
self.driver.execute_script('UIATarget.localTarget().frontMostApp().keyboard().buttons()["Done"].tap();');
@gaige Ok, I'll give it a go!
I've been delving around in the UIA data for the iPhone keyboard, and I'm not finding any helpful hidden buttons there, and UIAKeyboard doesn't have an explicit mechanism for hiding the keyboard, so we may be stuck with doing what the user does.
@gaige It's working for me in Java:
I've created a static final variable KEYBOARD_DONE with the following value:
"UIATarget.localTarget().frontMostApp().keyboard().buttons()['Done'].tap();";
Then I used the driver like this:
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript(KEYBOARD_DONE);
Thanks for all the help guys!
@raftheunis87 Thanks for the update. We'll continue trying to find some more universal solution. Unfortunately, apps can change the title of that button, so we need to seek a better way to find it.
@gaige Indeed. That's why I'd like to make a static final variable for every possible value of the "done" button e.g. hide, ok, done,...
(null) could not be tapped #254
Can anyone please help me out..i need done button event from keyboard..i am using c# Appium version 1.2.4.1..please do the needful
@gaige @raftheunis87 @jlipps
@amaanmemon issues are for bug, for this kind of issue use http://discuss.appium.io/ or https://gitter.im/appium/appium.
Avoid commenting on closed issue, unless you were previously involved in the discussion, open a new issue explaining your problem and link to it.
ok @sebv
I am trying to execute JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript(KEYBOARD_DONE); code but getting error like : org.openqa.selenium.WebDriverException: Not implemented in this context, try switching into or out of a web view
@jlipps :I am trying to hit Done button in my android real device but i am not getting any solution please could you help me on it.
You can simply do this by using the following command
driver.navigate().back();
Hi, Im using Cucumber+Page-object+selenium webdriver for creating mobile browser
caps = { :browserName => browser_name, :platform => "Android" }
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 500
@browser = Selenium::WebDriver.for(:remote, :url => "http://localhost:4723/wd/hub/", :http_client => client, :desired_capabilities => caps)
Now how to disable or hide android device key-pad during cucumber test run.
IOS Application hangs after tap using text #4624
- appium之hideKeyboard
- Appium之appium-desktop使用指南
- Appium之Mac配置Appium全过程
- appium框架之bootstrap
- Appium之java API
- appium框架之bootstrap
- appium框架之bootstrap
- appium框架之bootstrap
- Windows之Appium配置
- Appium 测试之setUP
- Appium之java API
- appium 之Xpath使用
- appium之Context切换
- appium之pip安装
- Appium使用之helloworld
- UII自动化之Appium
- Appium学习之踩坑合集
- appium 架构之bootstrap
- 基于注解的Spring MVC的URL与Controller映射关系提取的实现分析
- 一个关于strcpy()的问题,呵呵
- VS2012加载项目失败解决办法
- 写出以下标识符的命名规则
- 黑马程序员——java-集合框架
- appium之hideKeyboard
- poj1005
- Spring-MVC 源码分析(三):HandleMapping的配置与实现
- JavaScript window对象
- android中各种图标尺寸以及多分辨率支持方法
- Oracle创建定时任务与存储过程
- java中异常的处理
- 多条件下selected问题
- 微信公众平台java开发详解
Hi,
I'm experiencing an issue with the sendKeys method on a textfield. I'm using selenium webdriver in Java.
This is the piece of code:
WebElement helloButton = driver.findElement(By.name("Hello"));
WebElement textField = driver.findElement(By.tagName("textField"));
textField.sendKeys("Testuser");
helloButton.click();
When the sendKeys method is called, the keyboard appears on my iPhone simulator. But then it wants to press the helloButton, which is hidden underneath the keyboard and is gives an error (and a failing test ofcourse).
Is there a way to hide the keyboard before clicking the button?
Kind regards,
Raf Theunis