Python: selenium select
<p>I have a website with some different prices currencies you can select in a <code>&lt;select&gt;</code> with <code>&lt;option&gt;</code>, it looks like this:</p>

<pre><code>&lt;div class="menu" style="display: none;"&gt;
        &lt;p class="current-country"&gt;
            &lt;span class="flag store-7"&gt;&lt;/span&gt;
            Italia
        &lt;/p&gt;
        &lt;div class="currency-list"&gt;
            &lt;label for="currencyList"&gt;Cambia valuta:&lt;/label&gt;
            &lt;select name="currency-list" id="currencyList" data-bind="valueFromOptions: currencies, value: selectedCurrencyId"&gt;
                        &lt;option value="1" data-label="GBP"&gt;Â£ GBP&lt;/option&gt;
                        &lt;option value="2" data-label="USD"&gt;$ USD&lt;/option&gt;
                        &lt;option value="3" data-label="CAD"&gt;C$ CAD&lt;/option&gt;
                        &lt;option value="8" data-label="SEK"&gt;kr SEK&lt;/option&gt;
                        &lt;option value="9" data-label="NOK"&gt;kr NOK&lt;/option&gt;
                        &lt;option value="10" data-label="DKK"&gt;kr DKK&lt;/option&gt;
                        &lt;option value="14" data-label="CHF"&gt;â£ CHF&lt;/option&gt;
                        &lt;option value="19" data-label="EUR"&gt; â¬ EUR&lt;/option&gt;
                        &lt;option value="21" data-label="AUD"&gt;$ AUD&lt;/option&gt;
                        &lt;option value="10021" data-label="RMB"&gt;Â¥ RMB&lt;/option&gt;
                        &lt;option value="10042" data-label="HKD"&gt;$ HKD&lt;/option&gt;
                        &lt;option value="10064" data-label="NZD"&gt;$ NZD&lt;/option&gt;
                        &lt;option value="10078" data-label="SGD"&gt;$ SGD&lt;/option&gt;
                        &lt;option value="10085" data-label="TWD"&gt;NT$ TWD&lt;/option&gt;
                        &lt;option value="10123" data-label="RUB"&gt;ÑÑÐ±.  RUB&lt;/option&gt;
            &lt;/select&gt;
        &lt;/div&gt;
    &lt;/div&gt;
</code></pre>

<p>I want to iterate between the options available and each time print the price of the item, however, in this website, everytime you change the currency it reloads the page, so the code is not working for me, here is my code:</p>

<pre><code>driver.get(root_url[i] + str(num))  # open the page
el = driver.find_element_by_name('currency-list')  # find the &lt;select&gt;
for option in el.find_elements_by_tag_name('option'):  # for options inside
        div = driver.find_element_by_class_name('menu')  
        driver.execute_script("document.getElementsByClassName('menu')[0].style.display = 'block';")  # make the div containing the &lt;select&gt; visible
        option.click()
        elem = driver.find_element_by_class_name('current-price')  # find the price element and print it
        print(elem.get_attribute('innerHTML'), root_url[i] + str(num), option.get_attribute('innerHTML'))
driver.close()
</code></pre>

<p>I get an error:</p>

<pre><code>Traceback (most recent call last):
  File "C:/Users/dodob/PycharmProjects/Learning/Asosly.py", line 17, in &lt;module&gt;
    print(elem.get_attribute('innerHTML'), root_url[i] + str(num), option.get_attribute('innerHTML'))
  File "C:\Users\dodob\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 111, in get_attribute
    resp = self._execute(Command.GET_ELEMENT_ATTRIBUTE, {'name': name})
  File "C:\Users\dodob\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 461, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\dodob\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\dodob\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.StaleElementReferenceException: Message: Element not found in the cache - perhaps the page has changed since it was looked up
Stacktrace:
    at fxdriver.cache.getElementAt (resource://fxdriver/modules/web-element-cache.js:9454)
    at Utils.getElementAt (file:///C:/Users/dodob/AppData/Local/Temp/tmpb9cwfwq1/extensions/fxdriver@googlecode.com/components/command-processor.js:9039)
    at WebElement.getElementAttribute (file:///C:/Users/dodob/AppData/Local/Temp/tmpb9cwfwq1/extensions/fxdriver@googlecode.com/components/command-processor.js:12146)
    at DelayedCommand.prototype.executeInternal_/h (file:///C:/Users/dodob/AppData/Local/Temp/tmpb9cwfwq1/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
    at DelayedCommand.prototype.executeInternal_ (file:///C:/Users/dodob/AppData/Local/Temp/tmpb9cwfwq1/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
    at DelayedCommand.prototype.execute/&lt; (file:///C:/Users/dodob/AppData/Local/Temp/tmpb9cwfwq1/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)
</code></pre>

<p>I am sorry for my English, but anyway, what can I do to wait till the page reloads because I think it makes the issue.</p>

<p>If needed, I am trying to scrape some info from ASOS, example link <a href="http://www.asos.com/it/asos/asos-jeans-skinny-alla-caviglia-kaki/prd/6759361" rel="nofollow">here</a></p>

<pre><code># -*- coding: utf-8 -*-

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException


driver = webdriver.Chrome(\Path to chrome driver\)
driver.maximize_window()
baseurl = "http://www.asos.com/it/asos/asos-jeans-skinny-alla-caviglia-kaki/prd/6759361"
driver.get(baseurl)



def Getprice():
    selected_currency = driver.find_element(By.CSS_SELECTOR,".selected-currency")
    currentprice = driver.find_element(By.CSS_SELECTOR,".current-price")
    print "The price for selected current currency " + selected_currency.text + " is " +currentprice.text

def Setcurrency(text):
    one = driver.find_element(By.CLASS_NAME, "selected-currency")
    one.click()
    currentselection = driver.find_element_by_id("currencyList")
    select = Select(currentselection)
    select.select_by_visible_text(text)

def getallcurrencies():

    one = driver.find_element(By.CLASS_NAME, "selected-currency")
    one.click()
    el = driver.find_element_by_id("currencyList")
    currency =[]
    for option in el.find_elements_by_tag_name('option'):
        currency.append((option.text).encode('utf8'))
    return currency

list_of_currencies = getallcurrencies()
for currency in list_of_currencies:
    currentvalue= currency.decode('utf8')
    try:
        Setcurrency(currentvalue)
        time.sleep(2)
        element_present = EC.presence_of_element_located((By.CSS_SELECTOR,".current-price"))
        WebDriverWait(driver, 10).until(element_present)
        Getprice()
    except TimeoutException:
        print "Timed out waiting for page to load"
</code></pre>

<p>This program will first get all the avaiable currencies &amp; then print all the prices :</p>

<pre><code>The price for selected current currency Â£ GBP is Â£ 25,49
The price for selected current currency $ USD is $ 41,10
The price for selected current currency C$ CAD is C$ 50,85
The price for selected current currency kr SEK is SEK 318,66
The price for selected current currency kr NOK is NOK 326,83
The price for selected current currency kr DKK is DKK 254,93
The price for selected current currency â£ CHF is CHF 38,95
The price for selected current currency â¬ EUR is â¬ 33,99
The price for selected current currency $ AUD is $ 54,94
The price for selected current currency Â¥ RMB is Â¥ 245,12
The price for selected current currency $ HKD is HKD$ 310,89
The price for selected current currency $ NZD is NZD$ 62,13
The price for selected current currency $ SGD is SGD$ 55,41
The price for selected current currency NT$ TWD is NT$ 1.274,65
The price for selected current currency ÑÑÐ±. RUB is ÑÑÐ±. 2.338,81
</code></pre>

<p>Hope this will help in resolving your problem</p>

python selenium