Click element is not working in Appium, 'java.lang.NullPointerException' occurring - selenium

Eclipse Console Error:
Exception in thread "main" java.lang.NullPointerException
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83)
at amazon.StartApplication.main(StartApplication.java:58)
Appium log:
{"strategy":"id","selector":"in.amazon.mShop.android.shopping:id/sign_in_button","context":"","multiple":false}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"in.amazon.mShop.android.shopping:id/sign_in_button","context":"","multiple":false}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'in.amazon.mShop.android.shopping:id/sign_in_button' using 'ID' with the contextId: '' multiple: false
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=in.amazon.mShop.android.shopping:id/sign_in_button]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":{"ELEMENT":"2"}}
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"2"}
[info] [HTTP] <-- POST /wd/hub/session/fb4c547d-3a81-4b48-b6ff-cb14eb629138/element 200 28 ms - 87
Waited 60 seconds:
waited 60 seconds for a command
[debug] [AndroidDriver] Shutting down Android driver
Appium server is shutting down after the 1 minute

The default appium new command timeout value is 60 seconds, that's why appium server is shutting down the driver after 60 seconds. You can change the default timeout by setting in the capabilities as below:
capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 6000);
or
capabilities.setCapability("newCommandTimeout", 6000);

Firstly, NullPointerException in Java only occurs when the object it's referring to is null.
So it's possible that the variable you are using in this case is null and you are performing some calls on it, e.g.:
element.click ();
Here, element may be null.
So you need to handle this situation gracefully. If element is null, don't go to click on it, instead, log the error and exit.

Related

Nginx: What does 'upstream disconnected' log means?

I tried TLS connection from <10.220.17.192> to the external server(10.220.224.126) via nginx through reverse proxying, but at the external server, the connection is going to TIME_WAIT instead of getting ESTABLISHED.
From the nginx debug logs, I could see, "upstream disconnected". Does it means the external server closed the connected ?
2020/12/10 15:09:51 [debug] 10166#0: *11 event timer del: 4: 82382883
2020/12/10 15:09:51 [info] 10166#0: *11 proxy 10.220.17.192:50125 connected to 10.220.224.126:6515
2020/12/10 15:09:51 [debug] 10166#0: *11 malloc: 08DA8A10:16384
2020/12/10 15:09:51 [debug] 10166#0: *11 post event 08D8EFD0
2020/12/10 15:09:51 [debug] 10166#0: *11 epoll add event: fd:3 op:1 ev:80002001
2020/12/10 15:09:51 [debug] 10166#0: *11 event timer add: 3: 14400000:96778145
2020/12/10 15:09:51 [debug] 10166#0: *11 event timer: 3, old: 96778145, new: 96778145
2020/12/10 15:09:51 [debug] 10166#0: *11 delete posted event 08D8EFD0
2020/12/10 15:09:51 [debug] 10166#0: *11 SSL_read: 0
2020/12/10 15:09:51 [debug] 10166#0: *11 SSL_get_error: 5
2020/12/10 15:09:51 [debug] 10166#0: *11 peer shutdown SSL cleanly
2020/12/10 15:09:51 [debug] 10166#0: *11 posix_memalign: 08E22BE0:256 #16
2020/12/10 15:09:51 [debug] 10166#0: *11 write new buf t:0 f:0 00000000, pos 08DA8A10, size: 0 file: 0, size: 0
2020/12/10 15:09:51 [debug] 10166#0: *11 stream write filter: l:1 f:1 s:0
2020/12/10 15:09:51 [info] 10166#0: *11 upstream disconnected, bytes from/to client:0/0, bytes from/to upstream:0/0
I got the answer to the question after analysing logs from nginx source code.
nginx sends a post event if it receives connection closure from the external server.
2020/12/10 15:09:51 [debug] 10166#0: *11 post event 08D8EFD0
The manual page for SSL_read says, if SSL_read: 0
The read operation was not successful. The reason may either be a clean shutdown due to a “close notify” alert sent by the peer (in which case the SSL_RECEIVED_SHUTDOWN flag in the ssl shutdown state is set (see SSL_shutdown(3) and SSL_set_shutdown(3)). It is also possible that the peer simply shut down the underlying transport and the shutdown is incomplete. Call SSL_get_error() with the return value to find out whether an error occurred or the connection was shut down cleanly (SSL_ERROR_ZERO_RETURN)
2020/12/10 15:09:51 [debug] 10166#0: *11 SSL_read: 0
2020/12/10 15:09:51 [debug] 10166#0: *11 SSL_get_error: 5
2020/12/10 15:09:51 [debug] 10166#0: *11 peer shutdown SSL cleanly
For the below nginx logs , this is what the manual says,
2020/12/11 09:13:06 [debug] 11489#0: *1 SSL_shutdown: 1
If the peer already sent the “close notify” alert and it was already processed implicitly inside another function (SSL_read(3)), the SSL_RECEIVED_SHUTDOWN flag is set. SSL_shutdown() will send the “close notify” alert, set the SSL_SENT_SHUTDOWN flag and will immediately return with 1. Whether SSL_RECEIVED_SHUTDOWN is already set can be checked using the SSL_get_shutdown() (see also the SSL_set_shutdown(3) call).

Not able to find any element in appium for my mobile app

enter image description hereenter image description hereI am not able to find elements using any locators using appium in my mobile app, please check the attached screenshot and my code below
driver.findElementById("serviceUrl").sendKeys("ABC");
driver.findElementByClassName("android.widget.Button").click();
Appium server response
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//[#class='android.widget.EditText']","context":"","multiple":false}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '//[#class='android.widget.EditText']' using 'XPATH' with the contextId: '' multiple: false
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '//*[#class='android.widget.EditText']' using 'XPATH' with the contextId: '' multiple: false
[debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Matched JSONWP error code 7 to NoSuchElementError
Instead of this
driver.findElementById("serviceUrl").sendKeys("ABC");
Try this.
driver.findElementByClassName("android.widget.EditText").sendKeys("ABC");
As OP suggested you can try xapth as well.
driver.findElementByxpath("//*[#resource-id='serviceUrl']").sendKeys("ABC");
Or
driver.findElementByxpath("//*[#class='android.widget.EditText']").sendKeys("ABC");
You can try this:
driver.findElement(By.id("serviceUrl")).sendKeys("ABC");

APNS through socket on GCE stops working after a few hours

Here's a interesting problem I started facing since migrating from Heroku to Google Container Engine:
Since moving to GCE, after a few hours after server start/restart/deploy, out of nowhere, my Elixir application can't deliver push notifications to APNS any longer. I'm using the apns4ex library. Here is roughly what I found out so far:
Internally on init, the library opens a :ssl (erlang) socket to APNS and keeps recycling that inside a GenServer process
def connect_socket(host, port, opts, timeout_seconds) do
address = "#{host}:#{port}"
case :ssl.connect(host, port, opts, timeout_seconds * 1000) do
{:ok, socket} ->
APNS.Logger.debug("successfully connected to #{address}")
{:ok, socket}
{:error, reason} ->
APNS.Logger.error("failed to connect to push socket #{address}, reason given: #{inspect(reason)}")
{:error, {:connection_failed, address}}
end
end
Now, from hour x, after attempting to send a message, the library starts receiving the :ssl_closed message/callback to indicate that the SSL connection got closed
def handle_info({:ssl_closed, socket}, %{socket_apple: socket} = state) do
APNS.Logger.debug("ssl socket closed, returning :connect")
{:connect, {:error, "ssl_closed"}, %{state | socket_apple: nil}}
end
How it handles this is that it just let's the connection close and returns :connect, which will then re-connect to APNS (here)
Once push notifications stop working, the debug log always reports the following pattern on every message.
Attempt to send the message
Report "success sending" (nothing is being delivered to the phones. This message is caused by :ssl.send reporting :ok)
Then receive a ssl socket close message
Reconnect to gateway.push.apple.com (:ssl.connect returns :ok)
Repeat
send_package code:
def send_package(socket, packet) do
result = :ssl.send(socket, [packet])
case result do
:ok ->
APNS.Logger.debug("success sending ssl package")
{:error, reason} ->
APNS.Logger.warn("error #{reason} sending ssl package")
end
result
end
In contrast, on successful sending it stops at point 2.
Here is some raw log output from my app when sending a push (notice the last 9 lines showing the pattern I described)
01:41:14.820 request_id=fecds3h3s1so2825c44qfestvvvpv707 [debug] [APNS] #PID<0.20135.97> 23303051:1ad798 sending in poolboy transaction :myapp
01:41:14.821 request_id=fecds3h3s1so2825c44qfestvvvpv707 [debug] [APNS] #PID<0.20135.97> 23303051:1ad798 sending message
01:41:14.821 request_id=fecds3h3s1so2825c44qfestvvvpv707 [debug] [APNS] #PID<0.20135.97> 62064556:b12e98 sending in poolboy transaction :myapp
01:41:14.821 [debug] [APNS] #PID<0.349.0> 23303051:1ad798 handling cast :send
01:41:14.821 [debug] [APNS] #PID<0.349.0> 23303051:1ad798 message's payload looks good
01:41:14.821 request_id=fecds3h3s1so2825c44qfestvvvpv707 [debug] [APNS] #PID<0.20135.97> 62064556:b12e98 sending message
01:41:14.821 request_id=fecds3h3s1so2825c44qfestvvvpv707 [debug] [APNS] #PID<0.20135.97> 19048099:b3ed8e sending in poolboy transaction :myapp
01:41:14.822 [debug] [APNS] #PID<0.349.0> success sending ssl package
01:41:14.822 [debug] [APNS] #PID<0.349.0> 23303051:1ad798 success sending
01:41:14.822 [debug] [APNS] #PID<0.349.0> 23303051:1ad798 handle call :send received :ok
01:41:14.822 [debug] [APNS] #PID<0.348.0> 62064556:b12e98 handling cast :send
01:41:14.822 [debug] [APNS] #PID<0.348.0> 62064556:b12e98 message's payload looks good
01:41:14.823 request_id=fecds3h3s1so2825c44qfestvvvpv707 [debug] [APNS] #PID<0.20135.97> 19048099:b3ed8e sending message
01:41:14.823 request_id=fecds3h3s1so2825c44qfestvvvpv707 [info] Sent 200 in 22ms
01:41:14.823 [debug] [APNS] #PID<0.348.0> success sending ssl package
01:41:14.823 [debug] [APNS] #PID<0.348.0> 62064556:b12e98 success sending
01:41:14.823 [debug] [APNS] #PID<0.348.0> 62064556:b12e98 handle call :send received :ok
01:41:14.823 [debug] [APNS] #PID<0.347.0> 19048099:b3ed8e handling cast :send
01:41:14.824 [debug] [APNS] #PID<0.347.0> 19048099:b3ed8e message's payload looks good
01:41:14.824 [debug] [APNS] #PID<0.347.0> success sending ssl package
01:41:14.824 [debug] [APNS] #PID<0.347.0> 19048099:b3ed8e success sending
01:41:14.824 [debug] [APNS] #PID<0.347.0> 19048099:b3ed8e handle call :send received :ok
01:41:15.027 [debug] [APNS] #PID<0.348.0> ssl socket closed, returning :connect
01:41:15.029 [debug] [APNS] #PID<0.347.0> ssl socket closed, returning :connect
01:41:15.043 [debug] [APNS] #PID<0.349.0> ssl socket closed, returning :connect
01:41:15.207 [debug] [APNS] #PID<0.348.0> successfully connected to gateway.push.apple.com:2195
01:41:15.207 [debug] [APNS] #PID<0.348.0> successfully connected to socket
01:41:15.209 [debug] [APNS] #PID<0.347.0> successfully connected to gateway.push.apple.com:2195
01:41:15.209 [debug] [APNS] #PID<0.347.0> successfully connected to socket
01:41:15.214 [debug] [APNS] #PID<0.349.0> successfully connected to gateway.push.apple.com:2195
01:41:15.214 [debug] [APNS] #PID<0.349.0> successfully connected to socket
One theory is that GCE is closing the connection for being idle but this doesn't explain why another message after reconnect immediately results in the same pattern. Also why does the socket only close after sending with :ssl.send?
I have same issue with apns4erl, when socket close after trying send message, but problem was on my side, do not remember, it was either in the wrong certificate file or malformed messages

Cannot load url and then, cannot send login parameters

I'm trying to login automatically in tumblr, running the script proposed here but phantomjs only shows failed attempts:
[info] [phantom] Starting...
[info] [phantom] Running suite: 3 steps
[debug] [phantom] opening url: https://tumblr.com/login, HTTP GET
[debug] [phantom] Navigation requested: url=https://tumblr.com/login, type=Other,willNavigate=true, isMainFrame=true
[warning] [phantom] Loading resource failed with status=fail: https://tumblr.com/login
[debug] [phantom] Successfully injected Casper client-side utilities
[debug] [phantom] Logging in
[info] [remote] attempting to fetch form element from selector: '#signup_form'
[info] [phantom] Step anonymous 2/3: done in 2899ms.
[info] [phantom] Step _step 3/3: done in 2912ms.
[warning] [phantom] Casper.waitFor() timeout
[error] [phantom] Wait timeout of 100000ms expired, exiting.
Wait timeout of 100000ms expired, exiting.
I increased the original timeout script without success, my workstation uses:
- Windows 7 64bits
- Casperjs 1.1.0
- Phantomjs 1.9.1
thanks.
I finally found a solution for this issue.
Tumblr is using the TLSv1.2 encryption for their site while PhantomJS defaults to SSLv3.
To fix this, you can either call CasperJS with either:
casperjs tumblr.js --ssl-protocol=tlsv1
or
casperjs tumblr.js --ssl-protocol=any
With my version of casperjs and phantomjs, the cli ssl protocol parameter was being ignored, I had to put it in a config file instead:
casperjs browse.js --config=<(echo '{"sslProtocol": "any"}') --ignore-ssl-errors=true

Debug "about:blank" in CasperJs

I have the following simple casperjs script (I cannot name the actual URL - sorry) on a Windows 7 machine:
var casper = require('casper').create({verbose:true,logLevel: "debug"});
casper.start('https://[XXX].de', function() {
console.log(this.getCurrentUrl());
});
casper.run();
The Output states that it failed - and the current url is : "about:blank"
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: https://[XXX].de, HTTP GET
[debug] [phantom] Navigation requested: url=https://[XXX].de, type=Other, lock=true, isMainFrame=true
[warning] [phantom] Loading resource failed with status=fail: https://[XXX].de
[debug] [phantom] Successfully injected Casper client-side utilities
about:blank
[info] [phantom] Step 2/2: done in 39205ms.
[info] [phantom] Done 2 steps in 39309ms
When send a GET request with the Firefox RESTCLient Plugin - I get:
Status Code: 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: close
Content-Type: text/html
Date: Tue, 11 Dec 2012 11:09:37 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Server: unknown
Transfer-Encoding: chunked
My question is:
How can I debug this? Is this a known issue ?
Seems like the command line arguments passed to casperjs are not being passed to PhantomJS. I also ran into this issue and to fix this I ran my script as follows:
PhantomJS.exe --ignore-ssl-errors=true myscript.js
When I tried passing the parameters the other way around
PhantomJS.exe myscript.js --ignore-ssl-errors=true
it does not work and gives the same error as you have been facing.
To pass phantomjs parameters to casperjs, you can directly update your casper binary(casperjs.py on linux or casperjs.bat on windows).
On Linux, Open the casperjs.py, Update the CASPER_COMMAND array which is forming the phantomjs command and execute.
To add "--ignore-ssl-errors=yes", extend the CASPER_COMMAND by the following,
CASPER_COMMAND.extend(['--ignore-ssl-errors=yes']);
For the same, on windows or For more info can be found here