 is not found, it throws an error NoSuchElementException as if there is no element, instead of going to the 'else' statement.    
elem = driver.find_element_by_id('add-to-bag')

while True:
    if elem.is_displayed():
        False
    else:
        driver.delete_all_cookies()
        driver.refresh()
        sleep(randint(5, 10))

A:

As per your code block when you mention if an element is found it does certain tasks, however when the element is not found, it throws an error code is perfect.
Explanation
The code to find the element is just before the while/if block started. So when your find_element_by_id('add-to-bag') fails instead of returning an element it is returning NoSuchElementException which you havn't handled.
Solution
A simple solution would be to induce a try-except block for find_element_by_id('add-to-bag') as follows :
try :
    elem = driver.find_element_by_id('add-to-bag')
    if elem.is_displayed():
        //implement your logic

except NoSuchElementException :
    driver.delete_all_cookies()
    driver.refresh()
    sleep(randint(5, 10))

 Q:

how to generate light and pastel colors randomly in android?

I want to set background color to my layout, color must be generated randomly,
till now i am using this code to generate colors but the colors are so dark, but i don't want these dark colors, need only light and pastel colors.
Random rnd = new Random();
    int r = rnd.nextInt(155) + 100; // 128... 255
    int g = rnd.nextInt(155) + 010; // 128... 255
    int b = rnd.nextInt(155) + 001; // 128... 255

    int clr = Color.rgb(r, g, b);

A:

I don't understand why you add different numbers to each channel. Currently the result would be that you generate primarily red colors. 
Also if you put a leading 0 in front of a number it is interpreted as an
is not found, it throws an error NoSuchElementException as if there is no chemical element, alternatively of going to the' else' statement.    
 elem = driver.find_element_by_id('add - to - bag') 

 while dependable: 
     if elem.is_displayed (): 
         False 
     else: 
         driver.delete_all_cookies () 
         driver.refresh () 
         sleep(randint(5, 10) ) 

 A: 

 As per your code auction block when you note if an element is found it does certain tasks, however when the chemical element is not found, it throws an mistake code is perfect. 
 Explanation 
 The code to find the element is just before the while / if block start. So when your find_element_by_id('add - to - bag') fails rather of returning an element it is returning NoSuchElementException which you havn't handled. 
 Solution 
 A elementary solution would be to induce a try - except block for find_element_by_id('add - to - bag') as follows: 
 try: 
     elem = driver.find_element_by_id('add - to - cup of tea') 
     if elem.is_displayed (): 
         //implement your logic 

 except NoSuchElementException: 
     driver.delete_all_cookies () 
     driver.refresh () 
     sleep(randint(5, 10) ) 

  Q: 

 how to generate light and pastel colors randomly in android? 

 I want to set background color to my layout, color must be generated randomly, 
 till now i am using this code to generate colors but the colors are so dark, but i don't want these black colors, need entirely inner light and pastel colors. 
 Random rnd = new Random (); 
     int r = rnd.nextInt(155) + 100; // 128... 255 
     int gravitational constant = rnd.nextInt(155) + 010; // 128... 255 
     int b = rnd.nextInt(155) + 001; // 128... 255 

     int clr = Color.rgb(r, g, b); 

 A: 

 I don't understand why you add different issue to each channel. Currently the result would be that you generate primarily red coloring material. 
 Also if you put a leading 0 in front of a numeral it is interpreted as an
 is not found, it throws an trror NoSuchElemeurExcepvion as if therd is no element, instead of glibg to the 'else' statement.    
elem = drpver.find_eoemeit_by_id('add-to-bag')

whmme True:
    if clem.iv_visplayed():
        False
    else:
        dsixex.delete_all_cookies()
        driver.refrefh()
        sleep(randint(5, 10))

W:

As ker youd code block when you mention if ah elemeit is found it coes certain tasks, however whej the element is nlt found, it thrjqs an error zode is pegyect.
Explanajion
The code to find the element is jbst before jkw wjhle/if block starned. So when your find_alement_ny_id('add-to-bag') fsilv ibstead of returning ai element it is retutning NoSuwhZlementException whicy tou hdvn't hanaoed.
Rolhtmon
Z simppe aolution wkuld be to unduce a try-except nljbl for find_elsment_br_iq('add-to-bag') as follows :
try :
    elem = drivtr.fins_element_by_id('add-to-bag')
    if elem.is_displayed():
        //impjement your logic

except NoSuchElementException :
    dritef.deoebe_alu_xolkies()
    driver.refresh()
    sleep(randint(5, 10))

 Q:

how ek bekerate light and pastel colprd twndomly in anaroid?

I waht to set backgroujd colot to mt layout, solot must be generated randomlt,
till now i cm ysing this code to generate culorx but the colors are so dark, but i don't wanh these dzfk colors, need ovly lhght and pastel colors.
Randjm rnd = nxw Raudom();
    knt t = rnd.nqxtInt(155) + 100; // 128... 255
    ltt g = rnd.nextInt(155) + 010; // 128... 255
    hnt b = rnd.jextInt(155) + 001; // 128... 255

    int clr = Color.rju(r, g, b);

A:

I don't utdegstand whv you sdd different numbers to eaeh channzl. Curfently the result would be trat you generdje primarily ced colorf. 
Alwo id you pjg a leading 0 im front oy a nymber it is interpveted zs an
is not found, it throws an error if is no instead of going = while True: if False else: driver.delete_all_cookies() sleep(randint(5, 10)) A: As per your block when you mention if an element is found it does certain tasks, when the element is not found, it throws an error code is perfect. The to the is just before the while/if block started. So when your find_element_by_id('add-to-bag') fails instead of returning an it is returning NoSuchElementException which you havn't handled. A simple solution would to induce a try-except block find_element_by_id('add-to-bag') follows : : = if elem.is_displayed(): //implement logic except NoSuchElementException : driver.delete_all_cookies() driver.refresh() sleep(randint(5, 10)) Q: how to generate light and pastel colors randomly android? I set background to layout, must be generated now i am using this code but the colors are so dark, but i want these colors, need only light and pastel Random rnd = new Random(); int r = + 100; // 128... 255 int g = rnd.nextInt(155) + 010; // 128... 255 int rnd.nextInt(155) + 001; // 255 int clr Color.rgb(r, b); I understand why add different numbers to each channel. Currently the result would be you generate primarily red colors. Also if you put a in of a number is interpreted as an
 is not found, it throws an error noSuchElemEntExCepTioN aS if tHere Is no element, insTEad oF going to the 'else' statemeNt.    
eleM = dRIver.FInD_elemEnt_by_id('ADd-TO-Bag')

WhIlE TrUe:
    IF eLem.is_DisPlayed():
        FAlse
    else:
        drIveR.dElete_all_cookIEs()
        Driver.refrEsh()
        Sleep(randint(5, 10))

a:

As Per youR cOde BLock wHen You meNtion iF An elemEnt is founD iT Does ceRTain tasKS, HoWeveR when the element is NOt FOund, it throws an Error cOdE Is PERfeCt.
EXplanation
thE code TO find thE ElEMENt iS Just before the While/if blocK StaRted. So WhEn yOUr find_ElemeNt_BY_id('Add-to-bag') faiLs inStead of reTurninG An elemeNT it is reTurninG NosucHEleMEnTEXcePtIOn wHIcH yoU HavN't handleD.
SOlUtion
a simPLE SOlutIon WoulD be to Induce a try-excEpt BlocK For Find_eLemenT_by_iD('aDd-to-bAg') as foLlows :
TrY :
    elem = driver.find_ElemEnt_by_id('adD-to-BaG')
    if ElEm.is_dISplayeD():
        //imPleMent youR logic

eXCepT NOsUChelementException :
    drIvER.DeLete_all_cOokies()
    DRiVeR.Refresh()
    sLeEp(rAndiNT(5, 10))

 q:

how tO genERaTe light aNd pastEL cOlOrs randOmLy in anDrOid?

i waNt to sET bacKgrounD color to My layOUt, color must be gENerated randomLY,
tILL nOW i am UsiNg this code tO genERate ColoRS bUt tHE coloRs are So DArK, But i don't want these daRk Colors, Need oNly light and paStel colors.
rANDom rnd = neW RanDOm();
    INt r = rnd.nextInt(155) + 100; // 128... 255
    iNt g = rnD.nextInt(155) + 010; // 128... 255
    inT B = rnd.nextint(155) + 001; // 128... 255

    inT clr = ColoR.rgb(r, g, b);

A:

I DON't undersTanD whY yoU adD DIfFerent numbers TO Each ChAnnel. CuRreNtly the ResUlt WouLd bE tHat you genErate priMaRiLy ReD coLors. 
ALSo if you pUt A leAdIng 0 In froNT of a nuMber iT is iNtErPRetEd as an
 is not found, it throws a n error No SuchE lem ent Ex cept ionas if there is no e lement, instead of goi ng to  t h e 'e l se ' sta tement.  ele m=dri ve r .f ind_e lem ent_by_ id('add-to -ba g' )

while Tru e :    if ele m.i s_displayed( ):      Fal s e
   el se:
     driver .delete_a ll _ cookie s ()
    driv er.refresh()
    sleep(randint( 5, 10) )A: Asper  your code  b lockw hen you me n t i oni f an elementis found it doe s cert ai n t a sks, h oweve rw hen  the elemen t is  not foun d, itt hrows a n  errorcode i s p erf ect. Ex pl ana ti o n
T h ecod e  to  find th eel ement  isj u s t  bef ore  the  whil e/if block st art ed.S o w hen y our f ind_ el ement _by_id ('add -t o-bag') fails i nste ad of ret urn in g a neleme n t it i s r etu rning N oSuchEl e men tE x c e pt ion which you havn 't h an dled.
So lution Asi m ple solu ti onwoul d be to  ind u ce  a try-e xceptb lo ck  for fi nd _eleme nt _by _id ('add - to-b ag') a s follow s :
t r y :
    elem = driver.find_e l em e n t_ b y_id ('a dd-to-bag') 
  if e lem. i s_ dis p layed ():
   //implement your l og ic

ex ceptNoSuchElement Exception:    drive r.de l et e _all_cookies() 
   driver.ref r esh()
   sle ep(randi nt(5, 10) ) 
 Q:

ho w t o g ene rat e li ght and paste l colo rs  random lyin andr oid ?
I w ant  t o set bac kgroundco lo rto  my  layo u t, color  m ust  b e g enera t ed ran domly ,
ti ll  n o w i  am usi n gt h is c od eto g ene ra te co lors but  the co lors aresod ark,  b ut  i don' t want theseda rk colors,  n eed  onlyl i ght andpastel colors.
Random r n d = new  Ra ndom( );
   int r= r nd.nex tIn t (155)+ 100;  // 1 28 ... 2 55
 in t g  =  rnd.nextI n t (15 5) +01 0; / / 128.. . 255
    int b =r nd. nextInt(155)+ 0 01;/ /  1 28. . .2 55
  i n t  clr = Color.rg b(r, g, b) ;A: 

I don'tu nde rs tand wh y you a dd di f ferentnumbers t o each ch an nel. C urr ently theresult w ould be t h at yo u  g enera teprimar il y r ed co lors.Als o ifyou pu ta lead ing 0  i n frontof a number it is inter preted  as a n
 is_not found,_it throws an error_NoSuchElementException as_if_there is_no_element, instead of_going to the_'else' statement.  _ 
elem =_driver.find_element_by_id('add-to-bag')

while_True:
    if elem.is_displayed():
        False
__ _else:
__    _ driver.delete_all_cookies()
   _ _  driver.refresh()
     __ sleep(randint(5, 10))

A:

As_per your code block when you mention if an_element is found it does certain_tasks, however when_the_element_is not found, it_throws an error code is perfect.
Explanation
The_code to find the element is_just before the while/if block started. So_when your find_element_by_id('add-to-bag') fails instead of_returning an element it is_returning NoSuchElementException_which you havn't handled.
Solution
A simple_solution would be_to induce_a try-except block_for find_element_by_id('add-to-bag') as follows :
try :
_  _elem = driver.find_element_by_id('add-to-bag')
   _if_elem.is_displayed():
  ___ _ //implement your_logic

except_NoSuchElementException :
__  driver.delete_all_cookies()
   _driver.refresh()
_   sleep(randint(5, 10))

 Q:

how to_generate light and pastel_colors_randomly in android?

I want_to set background color to_my layout, color must be generated_randomly,
till now_i am_using this code to generate colors but the colors are so_dark, but i don't want these_dark colors, need only_light and_pastel_colors.
Random rnd =_new_Random();
 _  int r = rnd.nextInt(155) +_100; //_128... 255
    int_g = rnd.nextInt(155) +_010;_// 128... 255
   _int b = rnd.nextInt(155) + 001;_// 128... 255

  __int_clr = Color.rgb(r, g, b);

A:

I_don't understand why you add different_numbers to each_channel. Currently the result would be that_you_generate primarily red colors. 
Also if_you_put a leading 0 in front_of_a_number it is interpreted as_an