【发布时间】:2016-09-04 22:36:57
【问题描述】:
我想用旧链接替换新链接,可以是随机的,但两个链接不应该相同。
我写的逻辑是再次遍历内部循环,这可能导致链接设置为与之前的相同。
在函数中,我以字典格式传递值-
${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/"}
这是我用python+Robot框架写的函数——
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"
还有其他方法可以实现我想要做的事情吗?
【问题讨论】:
标签: python loops dictionary iterator logic