I need to obtain the attributes of an option under a select tag. However, i am unable to locate the select tag since the select tag does not have an id.
<div class="dropdown-wrapper">
<div class="mobile-dropdown">
<span class="mobile-arrow"></span>
<select>
<option data-url="/series/17948/commentary/1115802/new-zealand-vs-
pakistan-1st-odi-pak-in-nz-2017-18?innings=1" value="NZ Innings">NZ
Innings
</option>
<option data-url="/series/17948/commentary/1115802/new-zealand-vs-
pakistan-1st-odi-pak-in-nz-2017-18?innings=2" value="PAK
Innings">PAK Innings</option>
</select>
</div>
</div>
i tried two ways
Locating the select tag using find_elements_by_tag_name('select'), then obtaining all text within the select element, then locating the option tag using find_elements_by_xpath ("//option[contains(text(), text)]"). Once i located the option tag, i could use get_attributes to the required attribute. Not only does this seem very complex, it also doesn't work sometimes as it doesn't give the option text.
I tried using Select by using Select(find_element_by_css_selector("class"). The class name used is from the div tag. Then used select.select_by_index(1).getattribute(). However, i got an error "Select not defined".
1st Code
elem=driver.find_elements_by_tag_name('select')
options=[x.text for x in elem]
first_inn=options[2].split('\n')[1]
second_inn=options[2].split('\n')[0]
option=driver.find_elements_by_xpath("//option[contains(text(), first_inn)]")
option[7].get_attribute('data-url')
2nd Code
select = Select(driver.find_element_by_css_selector("mobile-dropdown"))
first_inn=select.select_by_index(1).get_attribute('data-url')
second_inn=select.select_by_index(0).get_attribute('data-url')
For the 1st code, i am getting ['','',''] and for the second code i am getting an error message "name 'Select' is not defined"