how to get input text from SearchView xamarin android? - xamarin.android

How to get input text from SearchView xamarin android?
I'm try searchView.GetQuery but error No Suggestions.
searchView.TextAlignment = TextAlignment.Center;
searchView.QueryTextChange += SearchView_QueryTextChange;
searchView.QueryTextSubmit += SearchView_QueryTextSubmit;
/*Error*/
//searchView.GetQuery

There are some differences between native Android and Xamarin.Android .
You just need to call searchView.Query; because it is a property in Xamarin (in native Android it is a method).
searchView.QueryTextChange += SearchView_QueryTextChange;
private void SearchView_QueryTextChange(object sender, SearchView.QueryTextChangeEventArgs e)
{
var searchView = sender as SearchView;
var text = searchView.Query;
}

Related

How to hide keyboard in iOS mobile automation using Appium

I am using iOS version of 10.2 and xcode version is 8.3.
Can anyone let me know how to hide the keyboard in iOS mobile automation using Appium?
programming language used: Java.
I tried driver.hideKeyboard(), but it doesn't work for me.
So, I tried with way:
by pressing the button specified key name and way
inspect key coordinate with appium and perform action. Both ways are work for me.
// way 1
driver.findElementByXPath(String.format("//XCUIElementTypeButton[#name='%s']", "Done")).click();
// way 2
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(new PointOption().withCoordinates(345, 343)).perform();
You could use java_client library methods:
driver.findElementByAccessibilityId("Hide keyboard").click();
driver.hideKeyboard(HideKeyboardStrategy.TAP_OUTSIDE);
driver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done");
I noticed that "Done" is not part of the keyboard group. So I tried to use the name "Done" as my reference to get the element. I tried this on my end and it works.
driver.findElementByName("Done").click();
The "driver" set declared as IOSDriver.
You can use below code snippet to hide keyboard:
driver.getKeyboard().pressKey(Keys.RETURN);
Solution for Python - 2020:
#staticmethod
def hide_keyboard(platform):
"""
Hides the software keyboard on the device.
"""
if platform == "Android":
driver.hide_keyboard()
elif platform == "iOS":
driver.find_element_by_name("Done").click()
i prefer to tap last key on keyboard for iOS instead of hide:
#HowToUseLocators(iOSXCUITAutomation = LocatorGroupStrategy.CHAIN)
#iOSXCUITFindBy(className = "XCUIElementTypeKeyboard")
#iOSXCUITFindBy(className = "XCUIElementTypeButton")
private List<IOSElement> last_iOSKeyboardKey;
#HowToUseLocators(iOSXCUITAutomation = LocatorGroupStrategy.CHAIN)
#iOSXCUITFindBy(className = "XCUIElementTypeKeyboard")
#iOSXCUITFindBy(iOSNsPredicate = "type == 'XCUIElementTypeButton' AND " +
"(name CONTAINS[cd] 'Done' OR name CONTAINS[cd] 'return' " +
"OR name CONTAINS[cd] 'Next' OR name CONTAINS[cd] 'Go')")
private IOSElement last_iOSKeyboardKey_real;
public boolean tapLastKeyboardKey_iOS() {
System.out.println(" tapLastKeyboardKey_iOS()");
boolean bool = false;
setLookTiming(3);
try {
// one way
//bool = tapElement_XCTest(last_iOSKeyboardKey.get(last_iOSKeyboardKey.size()-1));
// slightly faster way
bool = tapElement_XCTest(last_iOSKeyboardKey_real);
} catch (Exception e) {
System.out.println(" tapLastKeyboardKey_iOS(): looks like keyboard closed!");
System.out.println(driver.getPageSource());
}
setDefaultTiming();
return bool;
}
I tried using all of above method. In some case, it doesn't work perfectly. In my way, it will tap on top left of keyboard.
public void hideKeyboard() {
if (isAndroid()) {
driver.hideKeyboard();
} else {
IOSDriver iosDriver = (IOSDriver) driver;
// TODO: Just work for Text Field
// iosDriver.hideKeyboard();
// TODO: Tap outside of Keyboard
IOSElement element = (IOSElement) iosDriver.findElementByClassName("XCUIElementTypeKeyboard");
Point keyboardPoint = element.getLocation();
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(keyboardPoint.getX() + 2, keyboardPoint.getY() - 2).perform();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Since the IOS device keyboard doesn't have any "Done" or "Enter" buttons anymore so we can't use any of the Appium server utility interface like HideKeyboardStrategy.
I basically used the TouchAction class tap method to tap at top of the screen and dismiss the keyboard.
TouchAction touchAction = new TouchAction(driver);
int topY = driver.manage().window().getSize().height / 8;
int pressX = driver.manage().window().getSize().width / 2;
touchAction.tap(new PointOption().withCoordinates(pressX, topY)).perform();
Quick & simple solution :
I always try to tap anywhere on screen, may be on
Static text
Image
after entering to hide keyboard unless I explicitly has requirement of interacting with keyboard. This works pretty well for me. Try it :)

Xamarin Forms: Webview showing slight black line at bottom

I am creating an app using Xamarin Forms using PCL project. In ios, a black line is shown at the bottom of the web view only. I don't experience the same issue in android or windows 10.
As noted in the comments, I dealt with this before. It has to do with the background color of the webview. I have tried several things, the only thing that worked was setting this:
webView.Opaque = false;
webView.BackgroundColor = UIColor.Clear;
In a custom renderer on the UIWebView.
A complete implemented custom renderer would then look like this:
[assembly: ExportRenderer (typeof (WebView), typeof (WebViewRenderer))]
namespace YourApp.iOS.Renderers
{
public class WebViewRenderer : Xamarin.Forms.Platform.iOS.WebViewRenderer
{
protected override void OnElementChanged (VisualElementChangedEventArgs e)
{
base.OnElementChanged (e);
if (NativeView != null) {
var webView = (UIWebView)NativeView;
webView.Opaque = false;
webView.BackgroundColor = UIColor.Clear;
}
}
}
}

Xamarin Forms Plugin.Share not working for unknown reason

We have an image with a gesture recognizer, which calls the CrossShare.Current.Share method. On Android this works fine but on iOS it does not. No error is thrown and there doesn't seem to be any issues, but the share sheet does not appear and from the user's point of view nothing happens when you click the button.
Have I missed some permissions or something somewhere?
This is my method;
async void On_Share(object sender, EventArgs e)
{
if (CrossConnectivity.Current.IsConnected)
{
var message = "Check out this";
var title = "Share this";
await CrossShare.Current.Share(new ShareMessage { Text = message, Title = title}, new ShareOptions { ExcludedUIActivityTypes = new[] { ShareUIActivityType.PostToFacebook } });
}
else
{
NoInternetLabel.IsVisible = true;
}
}
It doesn't throw any errors and I can step through the method fine - it definitely hits the Share line. This problem is only showing on iOS, Android has no issues.
EDIT: Seems to be working fine (we've tried doing it natively as well - without plugin) but now I'm getting Warning: Attempt to present on whose view is not in the window hierarchy!

Add webview in Xamarin gtk form

I want to use Webview in Xamarin gtk Form. The problem is that i can't find Webview in toolbox.
Looking at this example i added some code in default MainWindow.cs code.
using System;
using Gtk;
using Xamarin.Forms;
public partial class MainWindow: Gtk.Window
{
public MainWindow () : base (Gtk.WindowType.Toplevel)
{
Build ();
WebView webView = new WebView
{
Source = new UrlWebViewSource
{
Url = "http://blog.xamarin.com/",
},
VerticalOptions = LayoutOptions.FillAndExpand
};
vbox2.Add (webView); //giving error since it webview is not widget.
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Gtk.Application.Quit ();
a.RetVal = true;
}
}
I am new to Xamarin and i don't know i can i create a xamarin gtk# tool that can run on OSX and windows.
I also want to fill htmlDocument and invoke click. Is it possible with xamarin gtk# webview

How to clear korean text in a textbox in windows phone 7 apps

when click on app bar button ..clear the text in textbox in windows phone 7 is not working.
private void ApplicationBarIconButton_Click(object sender, EventArgs e)
{
txtMessage.Text = string.Empty;
UpdateLayout();
}
Please suggest any solutions
This seems to be (as you thought) an issue with the Korean IME itself. Try setting focus to it first:
private void ApplicationBarIconButton_Click(object sender, EventArgs e) {
// Set focus to the page ensuring all TextBox controls are properly commited
// and that the IME session has been correctly closed.
this.Focus();
MessageTextBox.Text = "";
}
Shamelessly copy-pasted, read here for a closer look at the problem.

Resources