title: Scraping text from 3 connected dropdown menus
body: <p>I want to collect the data of three connected dropdown menus on a website.<br>
  It's about cars so the first is the brand, the second the model and the third is the motor type.<br>
  It's in a tree like structure.   </p>
  
  <p>An example: First you choose BMW then the second dropdown menu lets you choose a model lets say we take the X6. The third menu will now show us all possible motor configurations for <strong>this</strong> car. I want to scrape the whole "treelike" structure but I cant figure out how.</p>
  
  <p>Does anyone have any ideas?</p>
  
  <pre><code>    import selenium
      from selenium import webdriver
      from selenium.webdriver.support.ui import Select
      import xlsxwriter
      from time import sleep
  
      driver = webdriver.Firefox()
      url =
      driver.get(url)
      workbook = xlsxwriter.Workbook('Titel.xlsx')
      worksheet = workbook.add_worksheet()
  
      i=1
      q=37
      w=1
      x=0
      p=1
  
  
      while 0==0:
          select = Select(driver.find_element_by_xpath('//*[@id="typeSelectionField_1"]'))
          select2 = Select(driver.find_element_by_xpath('//*[@id="typeSelectionField_2"]'))
          select3 = Select(driver.find_element_by_xpath('//*[@id="typeSelectionField_3"]'))
      z1=len(select.options)
          if q&gt;=z1:
              break
          else:
              select.select_by_index(q)
  
              z2=len(select2.options)
              if w&gt;=z2:
                  w=1
                  q=q+1
  
                  select.select_by_index(q)
                  sleep(0.1)
                  select2.select_by_index(1)
                  sleep(0.1)
                  select3.select_by_index(1)
                  driver.find_element_by_xpath('//*[@id="access_buttons"]/div/button[1]').click()
  
              else:
                  select2.select_by_index(w)
  
                  z3=len(select3.options)
                  if i&lt;z3:
                      select3.select_by_index(i)
  
                      Typenbezeichnung = driver.find_element_by_xpath('//*[@id="form_kbanr"]/table/tbody/tr[2]/td[1]/label').text
                      Motor = driver.find_element_by_xpath('//*[@id="form_kbanr"]/table/tbody/tr[2]/td[2]/label').text
                      Baujahr = driver.find_element_by_xpath('//*[@id="form_kbanr"]/table/tbody/tr[2]/td[3]/label').text
                      worksheet.write('A%d'%p, Typenbezeichnung)
                      worksheet.write('B%d'%p, Motor)
                      worksheet.write('C%d'%p, Baujahr)
                      driver.find_element_by_xpath('//*[@id="access_buttons"]/div/button[1]').click()
                      p = p+1
                  elif i&gt;z3-1:
                      w=w+1
                      i=1
                      x=x+1
                      select.select_by_index(q)
                      sleep(0.1)
                      select2.select_by_index(1)
                      sleep(0.1)
                      select3.select_by_index(1)
                      driver.find_element_by_xpath('//*[@id="access_buttons"]/div/button[1]').click()
      workbook.close()
  `
  </code></pre>
  
  <p>This is the code. It seems to work at first, but it becomes slower over time and then throws an error, if it needs to much time to chose the next index.<br>
  I tried some things (the sleep(0.1) for example), but I can not really fix it.</p>