I have a problem with submitting searching field with android keyboard in Appium (selenium, java).I didn't find any working solution and stuck at this point. Please, help me.
I tried this:
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("UIATarget.localTarget().frontMostApp().keyboard().buttons()['Done\'].tap()");
But had an error:
org.openqa.selenium.WebDriverException: Not yet implemented. Please help us: http://appium.io/get-involved.html (WARNING: The server did not provide any stacktrace information)
You can't execute JS code that way in appium unless you are in a web view.
For hitting the search key, I would do it like this:
driver.sendKeyEvent(IOSKeyCode.ENTER);
You can send ENTER using:
driver.sendKeyEvent(66); // "66 - KEYCODE_ENTER
This link:
http://developer.android.com/reference/android/view/KeyEvent.html
will give you a list of all the Android KeyEvents, if you click on one of them you can see the actual code for it, like here:
http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_ENTER
Hope this helps!
If you are automating mobile web apps, then following is the best way to hide keyboard.
Map<String, Object> BackspaceKeyEvent = new HashMap<>();
BackspaceKeyEvent.put("key", "67");
((JavascriptExecutor)driver).executeScript("mobile:key:event", BackspaceKeyEvent);
This solution in JavaScript worked for me:
Java:
driver.executeScript("mobile: performEditorAction", ImmutableMap.of("action", "search"));
Javascript:
await driver.execute('mobile: performEditorAction', { action: 'search' });
Notice: This special native api just worked for Android.
This allowed me to submit a search command (same as clicking the search icon in the keyboard).
See http://appium.io/docs/en/commands/mobile-command/ for details on "mobile: performEditorAction".
Related
I did a search and I couldn't find this type of problem posted on stack overflow.
And I did read documentation on the https://chromedriver.chromium.org/capabilities but couldn’t find any meaningful examples. I found examples about add cookies but not about allow a cookie.
The problem:
Basically, I try to access and scrape a site but as soon as I try to access the url with:
webDriver.get(urlAddress);
a pop-up window appears which prompt me to accept all cookies.
My work around now is to click the button like in the code below.
List<WebElement> acceptAllCookies =
webDriver.findElements(By.id("ccc-notify-accept"));
if (!acceptAllCookies.isEmpty()) {
acceptAllCookies.get(0).click();
WebDriverWait wait = new WebDriverWait(webDriver, 2);
}
And then proceed with scraping.
I went to chrome://settings and add the site on to the “Sites that can always use cookies” and the pop up doesn’t show when I access it manually. But when I try programmatically the pop-up appears again.
I do not know how to load my chrome profile . I tried
ChromeOptions options = new ChromeOptions();
//Path to your chrome profile which allows
//cookyes from londonstockexchange
options.addArguments("user-data-dir= My User Data\\Default");
driver = new ChromeDriver(options);
But didn’t seem to work. I do not know how to configure the capabilities to allow cookies only for that specific site
Will be something like:
options.setCapability("____", _____);
I don't know what to add in the blanks to always allow cookie for a specific site.
Can someone please help fill in the blanks above or point me to some examples?
I am using Selenium and Java to write a test for Chrome browser. My problem is that somewhere in my test, I download something and it covers a web element. I need to close that download bar (I cannot scroll to the element). I searched a lot and narrowed down to this way to open the download page in a new tab:
((JavascriptExecutor) driver).executeScript("window.open('chrome://downloads/');");
It opens that new tab, but does not go to download page.
I also added this one:
driver.switchTo().window(tabs2.get(1));
driver.get("chrome://downloads/");
but it didn't work either.
I tried:
driver.findElement(By.cssSelector("Body")).sendKeys(Keys.CONTROL + "t");
and
action.sendKeys(Keys.CONTROL+ "j").build().perform();
action.keyUp(Keys.CONTROL).build().perform();
Thread.sleep(500);
but neither one even opened the tab.
It is because you can't open local resources programmatically.
Chrome raises an error:
Not allowed to load local resource: chrome://downloads/
Working solution is to run Chrome with following flags:
--disable-web-security --user-data-dir="C:\chrome_insecure"
But this trick doesn't work with Selenium Chrome Driver(I don't know actually why, a tried to remove all args that appears in chrome://version, but this doesn't helps).
So for me above solution is the only one that works:
C# example:
driver.Navigate().GoToUrl("chrome://downloads/")
There is another trick if you need to open downloaded file:
JavaScript example:
document.getElementsByTagName("downloads-manager")[0].shadowRoot.children["downloads-list"]._physicalItems[0].content.querySelectorAll("#file-link")[0].click()
Chrome uses Polymer and Shadow DOM so there is no easy way to query #file-link item.
Also you need to execute .click() method with JavaScript programatically because there is a custom event handler on it, which opens actual downloaded file instead of href attribute which point to url where you downloaded file from.
I started with this post and ended up with the solution given below. This one works in Chrome 71. First I highlighted the control and then clicked it.
The window object is actually the IWebDriver, the second method is called after the first one.
internal void NavigateToDownloads()
{
window.Navigate().GoToUrl("chrome://downloads/");
}
internal void OpenFirstDownloadLinkJS()
{
IJavaScriptExecutor js = (IJavaScriptExecutor) window;
js.ExecuteScript("document.getElementsByTagName('downloads-manager')[0].shadowRoot.children[4].children[0].children[1].shadowRoot.querySelectorAll('#content')[0].querySelector('#details > #title-area > #file-link').setAttribute('style', 'background: yellow;border: 2px solid red;');");
js.ExecuteScript("document.getElementsByTagName('downloads-manager')[0].shadowRoot.children[4].children[0].children[1].shadowRoot.querySelectorAll('#content')[0].querySelector('#details > #title-area > #file-link').click();");
}
Use this code (I wrote it in Python, but it should work in Java too with very slight modifications):
#switching to new window
driver.execute_script("window.open('');")
driver.switch_to.window(driver.window_handles[1])
#opening downloads
driver.get('chrome://downloads/')
#closing downloads:
driver.close()
I need to perform a key press combination on Selenium Chrome driver.
The action is not sending test to text box or clicking on a button.
I am actually not interested in sending keys to any specific web element.
For example, I would like to perform command+R (reload on Mac OS).
(Reloading is just an example for the explanation, not my ultimate goal)
My code is the following:
public static void keyPressCombnaiton() {
Actions action = new Actions(browser);
action.keyDown(Keys.COMMAND)
.sendKeys("r")
.keyUp(Keys.COMMAND)
.build()
.perform();
}
I have spend hours searching and trying only got no luck.
Any help is appreciated!
The WebDriver spec is element-focussed, and doesn't define any method to send keys to the window, the screen, to browser chrome - only to elements.
Use of the Selenium Actions class for Cmd-R works on my Mac in Firefox (45), but only when run in the foreground - and seemingly not at all in Chrome. Presumably this is down to differences in the implementations of the remote Keyboard implementation, which it's probably best not to rely upon.
The most efficient way and non-platform-specific way to request a page reload is using JavaScript:
((JavascriptExecutor) driver).executeScript("document.location.reload(true)");
However, JavaScript doesn't let you "just send keys".
The only other way is via the Java AWT Robot class:
Robot robot = new java.awt.Robot();
robot.keyPress(KeyEvent.VK_META); // See: http://stackoverflow.com/a/15419192/954442
robot.keyPress(KeyEvent.VK_R);
robot.keyRelease(KeyEvent.VK_R);
robot.keyRelease(KeyEvent.VK_META);
This "blindly" sends key combinations to whichever windows / components are on screen at the time, so if your browser window has been hidden or minimised, this will not work.
We are automating an iOS app using Appium and JAVA
We stuck at below point
How to open a keyboard view in appium to type in UIAtextbox field as sendkeys of webdriver is not working without it ?
Please help ....
You should not use send_keys on iOS. It is notoriously unreliable. (read more about that here)
Here's my implementation in python:
textfield = driver.find_element_by_class_name('UIATextField')
text = 'ABCDEF'
driver.execute_script("au.getElement('%s').setValue('%s')" % (textfield.id, text))
driver.hide_keyboard('return') # Close the keyboard with the return button
So what you need to do is:
Get the webelement/textfield
On the driver, call ExecuteScript
Pass in the the webelement's id and the value you want to set the textfield to
Optional: Hide the keyboard afterward
To add some clarity:
When you use sendkeys, do the textfield appear clicked?
What is the response from the server regarding the request of the sendkeys action?
Can you show the line where you do the inputing part?
This may be caused by a) Appium doesn't see the UItextbox b) The action is called before the textbox is usable(init phase) c)there is sth completely wrong with your line of code :)
Awaiting your answer
I have set the following properties:-
Set environment variables JAVA_HOME,path,ANT_HOME,path (using JDK version --> jdk1.7.0_40)
In Eclipse set the system Library, added all needed jars and select all jars in Order and Export.
Install the Firefox Version 24 and used the Selenium jar(selenium-server-standalone-2.41.0).
Giving no error while running the Java application, also no exception while not able to click on particular element.
sendKeys(Keys.ENTER) is working fine, but instead I need to use click() method.
Also code is working fine on other systems, I think I am missing something.
click() method is not giving any valid response, it makes me feel like its only declared not defined. I have tried on different websites, on different elements and with different types(xpath, css selector, name, id) but nothing worked for me. I took focus on that element by webdriver and also by highlighting the element using javascript code, its showing that particular element is present. I have performed other operations like entering username after clicking on that element, its performing well. I have worked with different browsers, different webpages also maximize the window using selenium but no positive response.
Any help will appreciate.
Thanks in advance
Hi the snippet below worked fine for me
public static void main(String[]args){
WebDriver appDriver;
appDriver = new FirefoxDriver();
appDriver.get("https://web210.qa.drfirst.com/login.jsp");
WebElement loginButton = appDriver.findElement(By.className("btn"));
loginButton.click();
appDriver.switchTo().alert().accept();
appDriver.close();
}