2016-05-10 2 views
0

古いリンクで新しいリンクを置き換えたい場合はランダムにすることができますが、両方のリンクを同じにしないでください。内側のループのマップの次の要素を反復する方法は、外側のループのマップの次の要素から来るのですか?

私が書いたロジックは、インナーループを繰り返しているため、リンクが以前と同じに設定される可能性があります。

機能では、私は、これは私のpython +ロボットのフレームワークで書かれている機能である辞書に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/"} 

を値を渡しています -

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" 

達成するための他の方法はあります私は何をしようとしていますか?

答えて

0

を参照することができますが、私は、キーと値の両方を使用していて、キーと値の形式でそれを使用したい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" 
0

辞書を使用する代わりに、リストを反復処理してみてください。

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() 

あなたはthis-

Getting the next element while cycling through list

+0

を試すことができます。とにかく、あなたの入力に感謝します。 –

+0

その場合は、次の反復アイテムを格納し、可能であればキー値を上書きしてみます。 –

関連する問題