0

I'm using Python 3.5.1, and I need to automate the download of a bunch of reports every morning (through Python). These are imported from a web platform, which is of restricted access. I started with the following piece of code, which works fine:

import webbrowser, time
webbrowser.open('mylink')
time.sleep(10)

However, I'm struggling now with a drop down box, from which I have to choose and submit the location. Here's the HTML necessary to solve the problem:

<SELECT id=PRMT_SV_N000000000C88F800x000000000E8040B8_NS_ class="clsSelectControl pv" aria-invalid=false style="WIDTH: auto" hasLabel="true">
  <OPTION selected>MDM Location Code</OPTION>
  <OPTION>--------------------------------------------</OPTION>
  <OPTION value=3002 dv="3002  Ontario 002">3002&nbsp;&nbsp;Ontario&nbsp;&nbsp;002</OPTION>
  <OPTION value=3004 dv="3004  Fresno, CA  004">3004&nbsp;&nbsp;Fresno,&nbsp;CA&nbsp;&nbsp;004</OPTION>
  <OPTION value=3005 dv="3005  San Diego

The Finish/submit button HTML:

<BUTTON onclick="oCV_NS_.promptAction('finish')" onmouseover="this.className = 'bp bph'" onmouseout="this.className = 'bp'" id=finishN000000000C88F800x000000000E804A58_NS_ class=bp name=finishN000000000C88F800x000000000E804A58_NS_>Finish</BUTTON>

I have omitted most of the options of course. For this exercise, imagine that I want to choose the first one, 3004 Fresno, CA 004.

Charles Clayton
  • 17,005
  • 11
  • 87
  • 120
  • You can't automate the browser without an extension module. There are a few if you search for them. – Peter Wood Jun 21 '16 at 18:16
  • @PeterWood, I'm trying to use selenium now. Do you know how to solve this problem with the selenium module? – Rodrigo Couto Jun 22 '16 at 18:18
  • You said you tried the methods [here](https://stackoverflow.com/questions/7867537/selenium-python-drop-down-menu-option-value/28613320), in what way did they not work? – Charles Clayton Jun 22 '16 at 21:42
  • @crclayton, just tried your code. The problem continues, showing a big message on the shell, which contains (Message: Unable to find element with id == PRMT_SV_N000000000C88F800x000000000E8040B8_NS_). I think the problem has to do with this id. – Rodrigo Couto Jun 22 '16 at 23:22
  • Try finding it by xpath instead of id – Charles Clayton Jun 22 '16 at 23:50
  • 1
    @RodrigoCouto I've no experience using Selenium from Python. If I were trying to do it I'd read the documentation and, if I had problems, search for specific solutions. – Peter Wood Jun 23 '16 at 04:55

1 Answers1

0

I'm assuming they don't work because you're trying to select using the wrong text or value using select_by_value() or select_by_visible_text(). Try selecting by index instead.

It's also strange that your select html element doesn't have quotes surrounding the id. It's possible that selenium isn't able to find it using find_element_by_id.

Try this:

from selenium import webdriver
from selenium.webdriver.support.ui import Select

...

webbrowser.open('mylink')

dropdown = driver.find_element_by_id("PRMT_SV_N000000000C88F800x000000000E8040B8_NS_")    
select = Select(dropdown)    
select.select_by_index(3) 
Charles Clayton
  • 17,005
  • 11
  • 87
  • 120