Selecting all elements that meet a criteria using selenium (python)
<p>Using selenium, is there a way to have the script pick out elements that meet a certain criteria? </p>

<p>What I'm exactly trying to do is have selenium select all Twitch channels that have more than X viewers. If you inspect element, you find this: </p>

<pre><code>&lt;p class="info"
    562
    viewers on
    &lt;a class="js-profile-link" href="/hey_jase/profile" 
    data-tt_content="live_channel" data-tt_content_index="1"
    data-tt_medium="twitch_directory" data-ember-action="1471"&gt;
    Hey_Jase
    &lt;/a&gt;
&lt;/p&gt;
</code></pre>

<p>It is hard to give an exact code as we only get a small sample of the HTML, but this should work if you tweak it a bit.</p>

<pre><code>from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.website.com')

source = driver.page_source
location = source.find('&lt;p class="info"')
source = source[location+16:] #adjust the +16 to maybe +15 or w/e depending on the exact source page you get
location_second = source.find('viewers on') #assuming there is a space between the actual number of viewers and the
source = int(source[:location_second-1])  #adjust the -1 to maybe -2 or w/e depending on the exact source page you get
if source &gt; x: # replace x with whatever number is your minimum viewers
    driver.find_element_by_class_name('js-profile-link') #might need to use x-path if you have multiple instances of the same class name
</code></pre>

python selenium selenium-webdriver