Just as the title implies I'm actually trying to get all the li
elements from a dropdown field and actually be able to compare those results to the ones from an specific .txt file.
The html/DOM contains this kind of list
< div id = "ProgramCategoriesAndCodes_chzn" class = "chosen-container groups-are-selectable show-selected-in-list chosen-container-multi modified-chzn chosen-container-active" style = "width: 291px;" > <ul class="chosen-choices">
<li class="search-field">
<input type="text" value=" " class="default" autocomplete="off" style="width: 266px;"></li>
</ul>
<div class="chosen-drop" style="left: 0px; width: 291px; top: 29px;">
<ul class="chosen-results">
<li id="ProgramCategoriesAndCodes_chzn_g_0" class="group-result active-result child-matched" title="AA - AEROBICS">AA - AEROBICS</li>
<li id="ProgramCategoriesAndCodes_chzn_o_1" class="active-result group-option" style="" title="AABD - BODYSHAPING WITH CORY EVERSON">AABD - BODYSHAPING WITH CORY EVERSON</li>
<li id="ProgramCategoriesAndCodes_chzn_o_2" class="active-result group-option" style="" title="AABP - Cory Everson's Gotta Sweat">AABP - Cory Everson's Gotta Sweat</li>
<li id="ProgramCategoriesAndCodes_chzn_o_3" class="active-result group-option" style="" title="AABS - Bodyshaping">AABS - Bodyshaping</li>
<li id="ProgramCategoriesAndCodes_chzn_o_4" class="active-result group-option" style="" title="AACF - Crunch Fitness">AACF - Crunch Fitness</li>
<li id="ProgramCategoriesAndCodes_chzn_o_5" class="active-result group-option" style="" title="AACJ - City Jam">AACJ - City Jam</li>
<li id="ProgramCategoriesAndCodes_chzn_o_6" class="active-result group-option" style="" title="AADA - GETTING FIT WITH DENISE AUSTIN">AADA - GETTING FIT WITH DENISE AUSTIN</li>
<li id="ProgramCategoriesAndCodes_chzn_o_7" class="active-result group-option" style="" title="AAFA - Fitness America Tour">AAFA - Fitness America Tour</li>
<li id="ProgramCategoriesAndCodes_chzn_o_8" class="active-result group-option" style="" title="AAKI - KIANA'S FLEX APPEAL">AAKI - KIANA'S FLEX APPEAL</li>
<li id="ProgramCategoriesAndCodes_chzn_g_9" class="group-result active-result child-matched" title="ABB - ESPN Radio Baseball">ABB - ESPN Radio Baseball</li>
<li id="ProgramCategoriesAndCodes_chzn_o_10" class="active-result group-option" style="" title="ABBAS - MLB All Star Game">ABBAS - MLB All Star Game</li>
<li id="ProgramCategoriesAndCodes_chzn_o_11" class="active-result group-option" style="" title="ABBDC - Series Del Caribe">ABBDC - Series Del Caribe</li>
<li id="ProgramCategoriesAndCodes_chzn_o_12" class="active-result group-option" style="" title="ABBDS - MLB Division Series">ABBDS - MLB Division Series</li>
<li id="ProgramCategoriesAndCodes_chzn_o_13" class="active-result group-option" style="" title="ABBLC - MLB League Championships">ABBLC - MLB League Championships</li>
<li id="ProgramCategoriesAndCodes_chzn_o_14" class="active-result group-option" style="" title="ABBMA - MLB Meet the Stars">ABBMA - MLB Meet the Stars</li>
<li id="ProgramCategoriesAndCodes_chzn_o_15" class="active-result group-option" style="" title="ABBML - MLB Regular">ABBML - MLB Regular</li>
<li id="ProgramCategoriesAndCodes_chzn_o_16" class="active-result group-option" style="" title="ABBMS - MLB Specials">ABBMS - MLB Specials</li>
<li id="ProgramCategoriesAndCodes_chzn_o_17" class="active-result group-option" style="" title="ABBSN - MLB Sunday Night Baseball">ABBSN - MLB Sunday Night Baseball</li>
<li id="ProgramCategoriesAndCodes_chzn_o_18" class="active-result group-option" style="" title="ABBWB - World Baseball Classic">ABBWB - World Baseball Classic</li>
<li id="ProgramCategoriesAndCodes_chzn_o_19" class="active-result group-option" style="" title="ABBWS - MLB World Series">ABBWS - MLB World Series</li>
<li id="ProgramCategoriesAndCodes_chzn_g_20" class="group-result active-result child-matched" title="ABK - Deportes Radio Basketball">ABK - Deportes Radio Basketball</li>
<li id="ProgramCategoriesAndCodes_chzn_o_21" class="active-result group-option" style="" title="ABKAS - NBA All Star Game">ABKAS - NBA All Star Game</li>
</ul>
</div>
</div>
The only thing I have so far (since I'm quite a noob at Selenium and Python), is this:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get(url)
elem = driver.find_element_by_xpath('//div[@id='ProgramCategoriesAndCodes_chzn']//ul[@class='chosen-results']
list_elem = elem.find_elements_by_tag_name("li")
for li in list_elem:
text = li.text
print(text)
I know that print doesn't actually serves any purpose at all but I'm lost here on how to actually achieve what I asked in first place :(
The actual text file contains info like this one:
AEROBICS
AE - AEROBICS
AE - BODYBUILDING
AE - MISCELLANEOUS
AMERICAS CLUB SOCCER
SOAM - ARGENTINE SOCCER
SOAM - ARGENTINE SOCCER RPT
SOAM - BRASILEIRAO SUB 20
SOAM - BRASILEIRAO SUB 20 RPT
SOAM - BRAZILIAN CHAMPIONSHIP
SOAM - BRAZILIAN CHAMPIONSHIP RPT
SOAM - COPA DO BRAZIL
SOAM - COPA DO BRAZIL RPT
SOAM - COPA MEXICO
SOAM - COPA MEXICO RPT
SOAM - COPA SAO PAULO JUNIOR
SOAM - LIGA FPD DE COSTA RICA
SOAM - LIGA MEXICANA
SOAM - LIGA MEXICANA RPT
SOAM - MAJOR LEAGUE SOCCER
SOAM - MAJOR LEAGUE SOCCER RPT
SOAM - USA SOCCER
Any help would be greatly appreciated!! Kind Regards.