Hi, could you please help me to sort the following problem out? I have been struggling with this problem for a long time. When I navigate to a web page and click on a web element then no errors occur, it looks like it was successful but on physical Android mobile I cannot see the click action was actually performed (even if I debug the test)
I would really appreciate if someone could try the same scenario on his Android device/simulator as I am really hopeless. I am attaching my code. The web page I use is public.Thank you in advance for any help or suggestions.
namespace Selenium_AndroidDriver
{
[TestFixture()]
public class Class7
{
public IWebDriver driver;
private string baseUrl;
private IWebElement LoginIcon;
Alright, this is interesting one
I spent some time on investigation, tried ChromeDriver and Selendroid, tried clicking by coordinates⌠Didnât work. Finally, I switched to native context and found out, that HTML code is âtransferredâ into native code, custom WebView, I suppose.
Basically, what you need to do, is:
1. Run AppiumDriver with ChromeDriver (or simply pass autoWebview capability with false) 2. Switch to native context 3. Find element and click on it. Example:
driver.FindElement(By.Name("Login")).Click();
To find right selectors, you can use uiautomatorviewer (doesnât work if Appium server is running), or page source function:
driver.getPageSource();
If you will have problems with getting other elements, let me know!
Hi Kirill, thank you very much for your time, it is much appreciated. I have been struggling with this problem for a long time. Regarding Selendroid, I was able to make it work through Selendroid but I was looking for a solution which I could use for both Android and IOS devices and Appium seems to be the way.
I am going to try your suggested solution today. I have got just a question related to the 2nd step as I am not entirely sure what do you mean by that?
Could you please provide me with your source code?
Thanks mate!
Neither AppiumDriver, neither Selendroid doesnât work for me within web context. Both work within native context though. I would suggest to stick to AppiumDriver driver and work with elements within native context. Simply switch to native context on launching browser. For me, autoWebview doesnât work properly⌠I opened an issue on that.
Your capabilities would be the same. Your code would be next:
Hey Kirill, I tried that but when i want to set the context to the âNATIVE_CONTEXTâ then I get the âNo such context foundâ error. Is the string âNATIVE_CONTEXTâ a constant or should it be replaced by a specific value for corresponding page. I am attaching my code (using c# binding). Thank you for your help.
[TestFixture]
public class Class1
{
public string baseUrl;
public AppiumDriver driver;
Thank you for your help Kirill. I have been able to click on the element! Need to get more information about context as it is still a bit cloudy for me though. When I open the page on a mobile device and then run google inspector to see web page elements then google crashes. So I do not know how to analyze the page yet but clicking on the element is a big step for me anyway.
If you have any useful links or information related to this problematic then they would be much appreciated.
Donât use debugger while running Appium server. Either use driver.getPageSource(); method to get source code, either use debugger, but shut down Appium server before.
Hi ,
Unfortunately, the context switch doesnât work for me , Iâm switching the context at the beginning of the test (from NATIVE to WEBVIEW) , and I do able to recognize / find the LogIn button , but once I click on it , nothing happens , but I do get 200 âOKâ response in Appium logs âŚ
Alright, could you try TouchActions one more time but using center coordinates of the element?
Letâs say element is your WebElement instance. To get center of the element you can use getLocation() and getSize() methods. Like that:
Point location = element.getLocation();
Dimension size = element.getSize();
double x = element.location.getX() + size.getWidth()/2.0;
double y = element.location.getY() + size.getHeight()/2.0;
Now try to click by coordinates x and y.
Also you should try JS (should be faster 2-3 times than TouchActions):
WebElement element = driver.findElement('...');
JavascriptExecutor js = (JavascriptExecutor) driver;
Point location = element.getLocation();
Dimension size = element.getSize();
double x = element.location.getX() + size.getWidth()/2.0;
double y = element.location.getY() + size.getHeight()/2.0
HashMap<String, Double> point = new HashMap<String, Double>();
point.put("x", x);
point.put("y", y;
js.executeScript("mobile: tap", point);
WebElement element = driver.findElement(By.id("cvm_btn_login_button")); //should be switched to name instead of text
JavascriptExecutor js = (JavascriptExecutor) driver;
Point p = element.getLocation();
Dimension size = element.getSize();
double x = p.getX() + size.getWidth() / 2.0,
y = p.getY() + size.getHeight() / 2.0;
HashMap<String , Double> point = new HashMap<String , Double>();
point.put("x" , x);
point.put("y" , y);
js.executeScript("mobile: tap", point);
itâs your code
Actually , no matter What Iâm trying , nothing works.
The one thing Iâve found which is working is some YUI js code which is being injected into the webpage , but Iâve some issues with proxy (the code should be downloaded from YUI repository)
info: --> POST /wd/hub/session/855425a3-10ec-4029-9b69-9b6d8eab8169/element {"using":"id","value":"cvm_login_button"}
info: [debug] Proxying command to 127.0.0.1:9515
info: [debug] Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/session/5ca490e8529b8c3282b1189d1dfe656d/element","method":"POST","json":{"using":"id","value":"cvm_login_button"}}
info: [debug] Proxied response received with status 200: {"sessionId":"5ca490e8529b8c3282b1189d1dfe656d","status":0,"value":{"ELEMENT":"0.07824705308303237-4"}}
info: <-- POST /wd/hub/session/855425a3-10ec-4029-9b69-9b6d8eab8169/element 200 51.607 ms - 103
info: --> GET /wd/hub/session/855425a3-10ec-4029-9b69-9b6d8eab8169/element/0.07824705308303237-4/location {}
info: [debug] Proxying command to 127.0.0.1:9515
info: [debug] Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/session/5ca490e8529b8c3282b1189d1dfe656d/element/0.07824705308303237-4/location","method":"GET"}
info: [debug] Proxied response received with status 200: "{\"sessionId\":\"5ca490e8529b8c3282b1189d1dfe656d\",\"status\":0,\"value\":{\"ceil\":{},\"clone\":{},\"floor\":{},\"round\":{},\"scale\":{},\"toString\":{},\"translate\":{},\"x\":38.40625,\"y\":312.5}}"
info: <-- GET /wd/hub/session/855425a3-10ec-4029-9b69-9b6d8eab8169/element/0.07824705308303237-4/location 200 17.603 ms - 175
info: --> GET /wd/hub/session/855425a3-10ec-4029-9b69-9b6d8eab8169/element/0.07824705308303237-4/size {}
info: [debug] Proxying command to 127.0.0.1:9515
info: [debug] Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/session/5ca490e8529b8c3282b1189d1dfe656d/element/0.07824705308303237-4/size","method":"GET"}
info: [debug] Proxied response received with status 200: "{\"sessionId\":\"5ca490e8529b8c3282b1189d1dfe656d\",\"status\":0,\"value\":{\"ceil\":{},\"clone\":{},\"floor\":{},\"height\":48,\"round\":{},\"scale\":{},\"toString\":{},\"width\":307}}"
info: <-- GET /wd/hub/session/855425a3-10ec-4029-9b69-9b6d8eab8169/element/0.07824705308303237-4/size 200 14.737 ms - 161
info: --> POST /wd/hub/session/855425a3-10ec-4029-9b69-9b6d8eab8169/execute {"script":"mobile: tap","args":[{"y":336,"x":191}]}
info: [debug] Pushing command to appium work queue: ["click",{"x":191,"y":336}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"click","params":{"x":191,"y":336}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: click
info: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][768,1184]
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"855425a3-10ec-4029-9b69-9b6d8eab8169"}
info: <-- POST /wd/hub/session/855425a3-10ec-4029-9b69-9b6d8eab8169/execute 200 121.564 ms - 76 {"status":0,"value":true,"sessionId":"855425a3-10ec-4029-9b69-9b6d8eab8169"}
Last line " execute " ⌠but nothing really happens with the button
You know what would be funny? If your button was truly broken, hence why nothing is happening. I only mention this as I had tunnel vision recently during some new test development. I couldnât figure out why my test code was returning a failure when I expected a pass. I thought my test scripts were bad, or Appium had some problem. It took me a while before I finally realized the app had a bug and was not working as expected, my tests were correct, and the reported failure was accurate.
@Christopher_Graham the thing is , the button works perfectly while tapping on it (real tapping) also I did managed to click / tap on the button by uisng some YUI js framework , the problem is I have some proxy issues and I cannot download the YUIâs code from the network , thatâs why Iâve decided to perform a click / tap by using a traditional appium / seleniumâs methods âŚ