How to create a loop that checks if "Remove" exists for multiple "Remove" [Helium] [Selenium] [Python]
<p>How to loop the below logic inside a script, till all are deleted then continue to the next text. </p>

<pre><code>if Text("Remove").exists():
click("Remove")
</code></pre>

<p>Explaination:</p>

<p>==============</p>

<p>WEBPAGE 1
CONTENTS:</p>

<p>â
A (REMOVE)
â
B (REMOVE)
â
C (REMOVE)</p>

<p>[ âRemoveâ is a clickable link that removes A, B ,C]</p>

<p>==============</p>

<p>Part of my script now:</p>

<p>if Text(âRemoveâ).exists():
    click(âRemoveâ)
    click(âOKâ)</p>

<p>===============</p>

<p>Result:</p>

<p>WEBPAGE 1
CONTENTS:</p>

<p>â</p>

<p>â
B (REMOVE)
â
C (REMOVE)</p>

<p>================</p>

<p>Above A is removed by the script.
My question is how can i loop that, so the result is:</p>

<p>===============</p>

<p>Result:</p>

<p>WEBPAGE 1
CONTENTS:</p>

<p>â</p>

<p>â</p>

<p>â</p>

<p>================</p>

<p>So for every text on the webpage that containts âRemoveâ
It executes the script untill there is no âRemoveâ anymore.</p>

<p>String have a replace method which you can directly use to replace the word with <code>''</code></p>

<pre><code>page = 'Lorem remove ipsum elit remove id justo eu, finibus remove'
page2 = 'Class aptent taciti sociosqu ad litora remove remove remove'

pageList = [page, page2]

for page in pageList:
    while 'remove' in page:
        page = page.replace('remove', '')
    print page

#Out: Lorem  ipsum elit  id justo eu, finibus 
#Out: Class aptent taciti sociosqu ad litora   
</code></pre>

<p>If it is specific HTML content replace that. </p>

<pre><code>page.replace('&lt;a id="Remove"&gt;Remove&lt;/a&gt;', '')
</code></pre>

<p>Let me know if that helps. </p>

python selenium helium