How can I use appium to find a element not visiable in a listview .driver.scroll_findElement_byname? - python-appium

How can I use appium to find a element which is not visible in a listview (maybe the element are located in the bottom,and I need to scroll many pages so that i can find the element )
I have used driver.scroll_find_element_by_name() ,but I got a error.
Appium:info: [debug] Didn't get a new command in 60 secs, shutting
down...
My code is as follows:
def scroll_find_element_by_name(self, element_name, time_wait=0.5):
'''
#param:
#rtn: True/False,
#usage:
'''
#
width,height=self.getScreenResolution()
for i in range(maxScrollTimes):
#
try:
self.assertRaises(NoSuchElementException, self.driver.find_element_by_name, element_name)
print "Scroll down " + str(i+1) + ' time to find ' + element_name
except:
print 'SUCCESS: ' + element_name + ' found'
return True
self.driver.swipe(width / 2, 5 * height / 8, width / 2, 3 * height / 8, 1500)#
sleep(time_wait)
print 'UNSUCCESS: ' + element_name + 'NOT found'
return False

For iOS:
el = self.driver.find_element_by_xpath('xpath_value')
self.driver.execute_script('mobile: scroll', {"element": el, "toVisible": True})
Modify 'find_element_by_xpath' to id or whatever you want it to be.
For Android:
I have written my own custom method which looks for the element - if found it will click else move further down. get_element in the below code snippet is one of my own custom method, you should change it to find_elemeny_by_xpath / id etc. Modify it to suit your needs.
def android_is_visible(self, locator):
for _ in xrange(15):
end_y = 950
try:
value = self.get_element(locator).is_displayed()
if value is True:
break
except NoSuchElementException:
self.driver.swipe(470, 1400, 470, end_y, 400)
#self.driver.swipe(start_x, start_y, end_x, end_y, duration=400)
self.driver.implicitly_wait(2)
continue
Also change value of 'end_y = 950' as per your screen size

Related

How can I disable ":w" from doing anything with the popup's buffer?

Here is a piece of code that creates the popup:
:function! PopupDemo()
let message = 'Hello World'
for i in range(10)
let message = message . ' ' . message
endfor
let s:win_buf = bufadd('popup-demo')
call bufload(s:win_buf)
call setbufline(s:win_buf, 1, message)
echo 'buf id: ' . s:win_buf
let width = 40
let height = 10
" Set the new window as the current window.
let enter = v:false
" Calculate the centering coordinates.
let win_x = &columns / 2 - width / 2
let win_y = &lines / 2 - height / 2
let s:win_id = nvim_open_win(s:win_buf, enter, {
\'relative': 'editor',
\'row': win_y,
\'col': win_x,
\'width': width,
\'height': height,
\'focusable': v:false,
\'style': 'minimal',
\'border': ['╔', '═','╗', '║', '╝', '═', '╚', '║'],
\'noautocmd': v:false,
\'bufpos': [0, 0]
\})
call nvim_win_set_option(s:win_id, 'wrap', v:true)
:endfunction
:function! PopupClose(timer)
if s:win_id != 0
call nvim_win_close(s:win_id, v:false)
endif
if s:win_buf != 0
call nvim_buf_delete(s:win_buf, {'force': v:true})
endif
:endfunction
After I create a buffer and a pop-up window through the PopupDemo() function, I do not call the PopupClose() function to close the window, but directly use the :wq command to save the file and exit neovim, the following error message will appear:
E37: No write since last change
E162: No write since last change for buffer "popup-demo"
I want file save instructions like ":w", ":wq" and ".wqall" to ignore the popup's buffer, how can I do this?
neovim version: v0.7.2
Normally buffers are related to files. Set 'buftype' option equal to nofile if not.
As it is Neovim-only code, you can replace bufadd('') with nvim_create_buf(v:false, v:true), so it sets the option while creating the buffer.

Infinite loop stops

I have googled this a lot and I can only find answers that relate to conditions within the loop being met. I want this loop to run infinitely (Hence while 1==1) and I'm testing it at the moment by just leaving it running in Thonny. It runs for variable lengths of time and then just stops. It doesn't exit the program or stop running, it just behaves as if it's waiting for something but there's nothing that I can see that it's waiting for. The shell doesn't report any errors or report that it has stopped running, it simply stops printing the string in the fourth line print statement.
I am very new to python and Linux and I have no idea how to debug this problem or where to look for the stopping point. Even running it in debug mode doesn't render any helpful information. Has anyone got any suggestions please?
The only other thing that I have tried outside of what I have said is I have tried running it on a fresh install of Raspberry Pi OS on three different Raspberry Pi 4 Model B computers. It behaves exactly the same on all of them.
while 1==1:
time.sleep(1)
cnt = 1
print('One = One loop ' + str(datetime.today()) + ' CNT: ' + str(cnt))
while Decimal(target_temperature()) - Decimal(0.3) >= Decimal(actual_temperature()) and switch_state() == 'currently not running':
print('Before heating loop ' + str(datetime.today()))
try:
if cnt == 1:
if Decimal(target_temperature()) - Decimal(0.3) >= Decimal(actual_temperature()) and switch_state() == 'currently not running':
print('First heating loop ' + str(datetime.today()))
requests.get('http://192.168.1.167/4/on')
log_db('On', str(target_temperature()), str(actual_temperature()))
time.sleep(225)
requests.get('http://192.168.1.167/4/off')
log_db('Off', str(target_temperature()), str(actual_temperature()))
time.sleep(300)
cnt = cnt + 1
if(cnt != 1):
if Decimal(target_temperature()) - Decimal(0.3) >= Decimal(actual_temperature()) and switch_state() == 'currently not running':
print('Second heating loop ' + str(datetime.today()))
requests.get('http://192.168.1.167/4/on')
log_db('On', str(target_temperature()), str(actual_temperature()))
time.sleep(180)
requests.get('http://192.168.1.167/4/off')
log_db('Off', str(target_temperature()), str(actual_temperature()))
time.sleep(300)
except Exception as e:
print(e)
Bearing in mind i don't know anything about python i will try to help.
1 - The first thing i would do is put the whole program in a try catch block. That wasy if anything bad happens you should be told about it
try:
<all your code>
except Exception as e2:
print('The whole thing errored' + e2)
2 - The delays are in seconds? For testing i would change every sleep to (30) so you can see what is going on without getting too bored waiting, when you have it working then change the times back.
3 - I would add some more print('got here!') like where you have if(cnt == 1) add else print('first loop wasnt 1 it was ' + cnt)
4 - try and make the code easier for you to read, when it gets actually run it will be so optimized that it wont bear any relation to what you write. So write it in a way that is easiest for you
5 - You turn it on and then off, but if the off failed it would never be turned off, you should assume that it will go badly and that will be the day you get a big bill. Try and stop it if an error occurs by adding another check if actualTemp > targetTemp then turn it off?
6 - the http request might take ages, specify a time in seconds you are prepared to wait like , timeout=60
try:
while 1==1:
try:
time.sleep(30)
targetTemp = Decimal(target_temperature())
actualTemp = Decimal(actual_temperature())
switchState = switch_state()
print('Doing it at ' + str(datetime.now()) + ' target ' + str(targetTemp) + ' actual ' + str(actualTemp) + ' switch ' + switchState)
if targetTemp - Decimal(0.3) >= actualTemp and switchState == 'currently not running'
print('too cold turning it for a bit!')
requests.get('http://192.168.1.167/4/on', timeout=60)
log_db('On', targetTemp , actualTemp)
else if actualTemp > targetTemp and switchState != 'currently not running'
print('too hot turning it off!')
requests.get('http://192.168.1.167/4/off', timeout=60)
log_db('Off', targetTemp , actualTemp)
else
print('Not doing anything!')
except Exception as e1:
print('Loop errored -> ' + e1)
except Exception as e2:
print('Whole thing errored -> ' + e2)
Thanks Billy the Kid. You were right. Sometimes the devices that the loop uses via HTTPRequests just don't reapond (the two functions use HTTPRequests) and sometimes they create errors that aren't caught in the loop. Putting the whole thing in a try/catch oddly did identify that. Problem solved.

ultisnips: How to "freeze" vim.current.window.cursor value for snippet

I had a snippet that used to work well (neovim 0.2.0)
snippet #= "comment ===" b
# `!p snip.rv = '=' * (78 - vim.current.window.cursor[1])`
# ${1:comments}
# `!p snip.rv = '=' * (78 - vim.current.window.cursor[1])`
endsnippet
This snippet is basically writing python comments block when triggered,
where the length of "=" depends on the position of the cursor.
For a few days now (I don't know which update makes it failing), the length of "=" is decreasing as long as I type my comment.
It looks like vim.current.window.cursor[1] is constantly re-evaluated.
Any idea how to "freeze" the value?
I finally found:
snippet #= "comment ===" b
`!p
if not snip.c:
width = int(vim.eval("78 - virtcol('.')"))
snip.rv = '# ' + '=' * width`
# ${1:comments}
`!p snip.rv = '# ' + '=' * width`
endsnippet

Image Upload in Progress 4gl

How to upload multiple images and save it locally or in server in progress 4gl and rename each images? tried to search google with keywords "upload images in progress 4gl / openedge" but no results.
Good day:
i found a few codes in the internet and after a few tweeks this is my code:
OS-CREATE-DIR VALUE(todr_name).
stat = OS-ERROR.
IF stat NE 0 THEN
MESSAGE "Directory not created. System Error #" stat.
ic = 0.
INPUT FROM OS-DIR (frdr_name).
REPEAT:
IMPORT cFileShort cFileLong cType.
/*MESSAGE /*cFileShort*/ /*cFileLong*/ cType VIEW-AS ALERT-BOX INFO.*/
/* File or Directory ? */
IF cType MATCHES "*F*" THEN DO:
ic = ic + 1.
/*MESSAGE "ShortFileName" cFileShort SKIP
"LongFileName" cFileLong VIEW-AS ALERT-BOX INFO.*/
MESSAGE STRING(ic) + ".jpg" VIEW-AS ALERT-BOX INFO.
OS-COPY VALUE (cFileLong) VALUE (SUBSTITUTE (todr_name, cFileShort )).
OS-RENAME VALUE(todr_name + "\" + cFileShort) VALUE(todr_name + "\" + STRING(ic) + ".jpg").
/*IF OS-ERROR = 0 THEN
OS-DELETE VALUE (cFileLong).*/
END.
END.

Panel doesn't execute )PNTS Section

I'm coding a ISPF Panel with "Point and shoot" elements. The elements say "yes" and "no" and the default cursor have to point to "yes".
1st Case:
Declaration of the fields: + TYPE(INPUT) PAS(ON)
When I use this declaration, the panel closes by pressing [enter] and generating rc = 0. However, the )PNTS section doesn't run.
2nd CASE:
Declaration of the fields: + TYPE (PS)
The )PNTS section runs by pressing [enter]. However, I cannot set the .cursor to the field "yes".
I tryed different ways with different field names (e.g. ZPS00001). I tryed to simulate Point and Shoot with Rexx, but nothing worked really fine.
Pressing enter will cause the point and shoot fields to be processed. However the cursor must be on one of the fields for the )PNTS section to set the value associated with a field. It would sound like panel may have not been coded correctly. PAS should be used for input or output fields and PS should be used for text fields. For instance if you have the following panel:
)ATTR
$ TYPE(PS)
! TYPE(OUTPUT) PAS(ON)
)BODY
+ --------------------- +
+ ===>_ZCMD +
+
$Field1 : _FLD +
$Field2 : _ABC +
$Field3 : !IN1 +
$Field4 : !IN2 +
)INIT
&INV1 = 111
&INV2 = 222
&INV3 = 333
)REINIT
REFRESH(*)
)PROC
)PNTS
FIELD(IN1) VAR(INV1) VAL(ON)
FIELD(IN2) VAR(INV2) VAL(OFF)
FIELD(ZPS00001) VAR(INV3) VAL(1)
FIELD(ZPS00002) VAR(INV3) VAL(2)
FIELD(ZPS00003) VAR(INV3) VAL(3)
FIELD(ZPS00004) VAR(INV3) VAL(4)
)END
With the following REXX exec:
/* REXX */
RCC = 0
INV1 = 0
INV2 = 1
DO WHILE RCC = 0
ADDRESS ISPEXEC 'DISPLAY PANEL(PAS)'
RCC = RC
SAY INV1 '-' INV2 '-' INV3
END
You can test the values of inv1, inv2 and inv3 based on where you put the cursor when you hit enter. You will get 1, 2, 3 or 4 if the cursor in on field1, field2, field3 or field4. If it is on IN1 or IN2 then you get ON or OFF. It all depends on where the cursor is positioned when ENTER is hit. Based on the example you can see point and shoot is not limited to Menus. Hope the example helps.
Marv Knight