I want to replace the new link by the old one, which can be random, but both link should not be the same.
The logic I have written is iterating over the inner loop again, which can cause the link to be set as the same as previous one.
In the function I am passing the value in dictionary format-
${oldLinks}= Set Variable {"Facebook":"https://www.facebook.com/","Stack Overflow":"http://stackoverflow.com/"}
${newLinks}= Set Variable {"Discovery":"http://www.discovery.com/","HowStuffWorks":"http://www.howstuffworks.com/"}
This is the function I have written in python + Robot framework -
def edit_favorites(d,oldLinks,newLinks):
oldLinks=json.loads(oldLinks)
newLinks=json.loads(newLinks)
BookmarkLinks=oldLinks
NewBookarks=newLinks
d.press.back()
d(hamBergBtn).click()
d(favorites).click()
for key,val in BookmarkLinks.iteritems():
logger.info("Editing the favorites",html=False,also_console=True)
logger.info("key url"+key,also_console=True)
# if(d({'textContains':key}))==None:
# d({'scrollable':True}).scroll.toEnd()
for key1,val1 in NewBookarks.iteritems():
d({'textContains':key}).long_click()
if d({'textContains':"Copy link URL"}).exists & d({'textContains':"Edit"}).exists & d({'textContains':"Remove"}).exists & d({'textContains':"Cancel"}).exists:
logger.info("coming here, to edit",also_console=True)
d({'text':'Edit'}).click()
d({'resourceId':'com.ex.browser:id/title'}).click()
if d({"focused":"true"}):
d({'resourceId':'com.ex.browser:id/title'}).set_text(key1)
d({'resourceId':'com.ex.browser:id/address'}).click()
if d({"focused":"true"}):
d({'resourceId':'com.ex.browser:id/address'}).set_text(val1)
d({'text':'Save'}).click()
break
else:
raise RuntimeError,"Pop up doesn't contain the required fields"
Is there any other way to achieve what I am trying to do?
Instead of using dictionary, try iterating over list.
from itertools import cycle
li = [link1,link2]
running = True
licycle = cycle(li)
# fetch the next element
nextelem = licycle.next()
while running:
thiselem, nextelem = nextelem, licycle.next()
You can refer this-
You can try this-
def edit_favorites(d,oldLinks,newLinks):
oldLinks=json.loads(oldLinks)
newLinks=json.loads(newLinks)
OldBookmarkLabel=oldLinks.keys()
OldBookmarkURL=oldLinks.values()
NewBookarksLabel=newLinks.keys()
NewBookarksURL=newLinks.values()
# d.press.back()
for i in range(len(OldBookmarkLabel)):
logger.info("Editing the favorites",html=False,also_console=True)
logger.info("key url "+OldBookmarkLabel[i],also_console=True)
# if(d({'textContains':key}))==None:
# d({'scrollable':True}).scroll.toEnd()
d({'textContains':OldBookmarkLabel[i]}).long_click()
if d({'textContains':"Copy link URL"}).exists & d({'textContains':"Edit"}).exists & d({'textContains':"Remove"}).exists & d({'textContains':"Cancel"}).exists :
logger.info("coming here, to edit",also_console=True)
d({'text':'Edit'}).click()
d({'resourceId':'com.citrix.browser:id/title'}).click()
if d({"focused":"true"}):
d({'resourceId':'com.citrix.browser:id/title'}).set_text(NewBookarksLabel[i])
d({'resourceId':'com.citrix.browser:id/address'}).click()
if d({"focused":"true"}):
d({'resourceId':'com.citrix.browser:id/address'}).set_text(NewBookarksURL[i])
d({'text':'Save'}).click()
else:
raise RuntimeError,"Pop up doesn't contain the required fields"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.