I have been trying to automate some really boring stuff (because of how tedious I have been making mistakes and I want to reduce them as close as zero as I can), in essence I got assets that have to be entered into our system one by one through a horrible process. This is my problem right now:
My objective is to select the option 'CELL PHONES' on the drop down list (ctl00_CPH1_cmbClasses_DropDown). Also for security reasons and the fact that it is a protected Corporate Page (I already handled login and navigation till this point) I can only show snippets of the code as to not compromise it.
EDIT 1 (Modified this to add more of the HTML code)
<td class="rcbInputCell rcbInputCellLeft" style="width:100%;"><input name="ctl00$CPH1$cmbClasses" type="text" class="rcbInput radPreventDecorate" id="ctl00_CPH1_cmbClasses_Input" value="" /></td><td class="rcbArrowCell rcbArrowCellRight"><a id="ctl00_CPH1_cmbClasses_Arrow" style="overflow: hidden;display: block;position: relative;outline: none;">select</a></td>
</tr>
</table><div class="rcbSlide" style="z-index:6000;"><div id="ctl00_CPH1_cmbClasses_DropDown" class="RadComboBoxDropDown RadComboBoxDropDown_WebBlue " style="display:none;width:140px;"><div class="rcbScroll rcbWidth" style="width:100%;"><ul class="rcbList" style="list-style:none;margin:0;padding:0;zoom:1;"><li class="rcbItem"></li><li class="rcbItem">CELL PHONES</li><li class="rcbItem">CELLULAR PHONE SCRAP (WITHOUT BATTERIES)</li><li class="rcbItem">COMPUTER - DESKTOP</li><li class="rcbItem">COMPUTER -TOWER</li><li class="rcbItem">COMPUTERS</li><li class="rcbItem">COMPUTERS - SFF</li><li class="rcbItem">COPPER BEARING - LOW GRADE</li><li class="rcbItem">Desktop</li><li class="rcbItem">FLOPPY DISK DRIVES</li><li class="rcbItem">GARBAGE - NON HAZARDOUS</li><li class="rcbItem">LAPTOPS</li><li class="rcbItem">LCD Monitor</li><li class="rcbItem">MISC. ELECTRONICS</li><li class="rcbItem">MISCELLANEOUS</li><li class="rcbItem">MODEMS</li><li class="rcbItem">NETWORK EQUIPMENT</li><li class="rcbItem">OCC</li><li class="rcbItem">PHONES - DIGITAL</li><li class="rcbItem">PRINTERS</li><li class="rcbItem">SERVERS</li><li class="rcbItem">SERVERS - TOWER</li><li class="rcbItem">Telecom Equipment</li><li class="rcbItem">Telephone</li><li class="rcbItem">Telephone Accessory</li><li class="rcbItem">TEST EQUIPMENT</li><li class="rcbItem">WIRE & CABLE - MISC. </li></ul></div></div></div><input id="ctl00_CPH1_cmbClasses_ClientState" name="ctl00_CPH1_cmbClasses_ClientState" type="hidden" />
</div>
This is the combobox code from the page (corporate web form), I am trying to select it but my current codes and attempts (some from other post here in Stack Overflow) have failed so far, this is what I have attempted so far:
def fast_multiselect(driver, element_id, labels):
select = browser.find_element_by_id('ctl00_CPH1_cmbClasses_DropDown')
for option in select.find_element_by_name('CELL PHONE'):
if option.text in labels:
option.click()
This was my first attempt (several iterations of the same code) and the result was Python not listing any errors but not selecting the option I wanted so following advice from here I went for this:
selectDropDownList = browser.find_element_by_id("ctl00_CPH1_cmbClasses_DropDown > option[value='CELL PHONE']").click()
And this was the result:
Traceback (most recent call last): File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\Scripts\Add Asset.py", line 77, in selectDropDownList = browser.find_element_by_id("ctl00_CPH1_cmbClasses_DropDown > option[value='CELL PHONE']").click() File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 269, in find_element_by_id return self.find_element(by=By.ID, value=id_) File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element 'value': value})['value'] File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute self.error_handler.check_response(response) File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"ctl00_CPH1_cmbClasses_DropDown > option[value='CELL PHONE']"} (Session info: chrome=52.0.2743.116) (Driver info: chromedriver=2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129),platform=Windows NT 10.0.10586 x86_64)
I continued marching forward and this was my last attempt:
Select(browser.find_element_by_id('ctl00_CPH1_cmbClasses_DropDown')).select_by_value('CELL PHONES')
And the result is:
Traceback (most recent call last): File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\Scripts\Add Asset.py", line 78, in Select(browser.find_element_by_id('ctl00_CPH1_cmbClasses_DropDown')).select_by_value('CELL PHONES') File "C:\Users\AMSUser\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\support\select.py", line 39, in init webelement.tag_name) selenium.common.exceptions.UnexpectedTagNameException: Message: Select only works on elements, not on