1

I'm trying to cycle through a drop-down menu where each element is a link to a different page. I would like to cycle through all the elements of the drop down menu by clicking on them one at a time, going to the page it directs me to, downloading something from that page, and then clicking on the drop down menu (which exists on every page) and going to the next option on the menu.

This is the code of the drop down menu:

<div class="account-selection">
 <input type="hidden" name="fromResourceNode" value="/content/customer/my_account/jcr:content/mainpar/myaccount">
 <input type="hidden" name="extraTabInfo" id="extraTabInfo" value="">
 <input type="hidden" name="extraAccordionInfo" id="extraAccordionInfo" value="">
 <label for="selectAcct" class="hidden">Select your account</label>
 <select id="selectAcct" name="currAcctNumber">
   <option value="1001140692">1001140692, 4 BEECH </option>
   <option value="1001140648">1001140648, BEECH 3</option>
   <option value="1001257836">1001257836, 7C BEECH </option>
   <option value="1001265171">1001265171, 4E BEECH </option>
   <option value="1001238965">1001238965, 4D BEECH </option>

When i try using:

select = Select(browser.find_element_by_id('selectAcct'))
select.select_by_value('1001140648')
Keys.ENTER

For whatever reason the selenium browser is not being directed to the next page that actually clicking on the link would take me to. Any idea what I am doing wrong? I have all the imports set up correctly and everything else to the program is running smoothy.

Also, is there any simple way to go through the entire drop down menu without having to fill in the actual option values manually?

Thanks!

2
  • Can you update the question with a bit more of the outerHTML? Commented Feb 27, 2018 at 6:37
  • I updated it with more of the HTML. Is this better? Commented Feb 27, 2018 at 14:27

2 Answers 2

1

the Keys.ENTER isn't really doing anything than identifying the ENTER key. to press it,

select.send_keys(Keys.ENTER)

alternatively, if the select is in a form, just do

select.submit()

(you might consider renaming the element to "select_account" to avoid possible confusion).

Also, to get a list of all of the options:

available_options = select.options

which you could then loop through (though, I wonder if you'll encounter a StaleElementException on page after the first...you may need to enumerate them first, then cycle through them)

Sign up to request clarification or add additional context in comments.

1 Comment

It tells me 'select' has no attribute 'submit'.
1

As per the HTML you have shared it is inconclusive why the browser is not being directed to the next page perhaps it seems you are trying to invoke select_by_value() before the <select> element and <option> elements load properly. So a possible solution will be to induce WebDriverWait for the element to be selectable as follows :

WebDriverWait(driver, 20).until(EC.element_to_be_selected((By.XPATH, "//select[@id='selectAcct' and @name='currAcctNumber']")))
select = Select(browser.find_element_by_xpath("//select[@id='selectAcct' and @name='currAcctNumber']"))
select.select_by_value('1001140648')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.