Element is not currently visible and so may not be interacted with, Selenium Dropdown Box Python -


i need through pages on webpage. there dropdown box in left upper corner on of these pages, available cities. want visit every page, choosing every position in dropdown box. dropdown box has scrollbar, , when want choose option below it, gives me exception message:

message: element not visible , may not interacted stacktrace:     @ fxdriver.preconditions.visible (file:///tmp/tmphwlmyh/extensions/fxdriver@googlecode.com/components/command-processor.js:9981)     @ delayedcommand.prototype.checkpreconditions_ (file:///tmp/tmphwlmyh/extensions/fxdriver@googlecode.com/components/command-processor.js:12517)     @ delayedcommand.prototype.executeinternal_/h (file:///tmp/tmphwlmyh/extensions/fxdriver@googlecode.com/components/command-processor.js:12534)     @ delayedcommand.prototype.executeinternal_ (file:///tmp/tmphwlmyh/extensions/fxdriver@googlecode.com/components/command-processor.js:12539)     @ delayedcommand.prototype.execute/< (file:///tmp/tmphwlmyh/extensions/fxdriver@googlecode.com/components/command-processor.js:12481) 

heres code :

#!/bin/env/python # -*- coding: utf-8 -*-  import time selenium.webdriver.common.by import selenium.webdriver.support.wait import webdriverwait selenium import webdriver selenium.common.exceptions import nosuchelementexception selenium.webdriver.support import expected_conditions ec selenium.webdriver.common.by import selenium.webdriver.support.ui import select  def get_browser():     return webdriver.firefox()   main_page_url = "http://example.com/" basic_url = 'http://example.com/ogloszenia-kobiet.html'  def get_city_list(url) :      age_accept_button_xpath = ".//*[@id='columns']/div/div[2]/section/div/div/div/div/div/div[2]/div[2]/a[2]"     combobox_xpath = ".//*[@id='select_city']/li/form/div/button"     combobox_option_xpath = ".//*[@id='select_city']/li/form/div/div/ul/li[%s]/a/span[1]"     choose_button_xpath = ".//*[@id='select_city']/li/form/button"      pages = []      try:         browser = get_browser()         wait = webdriverwait(browser, 100)         browser.get(main_page_url)         time.sleep(2)          button_age_accept = browser.find_element_by_xpath(age_accept_button_xpath)         button_age_accept.click()         time.sleep(10)          browser.get(url)          = 2          while(true) :             try :                  button_combobox = browser.find_element_by_xpath(combobox_xpath)                 button_combobox.click()                 time.sleep(5)                  element_xpath = combobox_option_xpath %                 option_in_combobox = browser.find_element_by_xpath(element_xpath)                 # wait.until(ec.invisibility_of_element_located((by.xpath, element_xpath)))                 # option_in_combobox = webdriverwait(browser, 10).until(lambda browser : browser.find_element_by_xpath(element_xpath))                 option_in_combobox.click()                 time.sleep(5)                  button_choose = browser.find_element_by_xpath(choose_button_xpath)                 button_choose.click()                 time.sleep(5)                  pages.append(browser.current_url)                  += 1             except exception, e:                 print e                 break          browser.close()         return pages      except exception, e:         info = 'generic exception\n'         print e         return []  get_city_list(basic_url) 

i tried scroll bar, tried move down, still, no effect. can scroll pages @ top of drop down box:

#!/bin/env/python # -*- coding: utf-8 -*-  import time selenium.webdriver.common.by import selenium.webdriver.support.wait import webdriverwait selenium import webdriver selenium.webdriver.common.action_chains import actionchains selenium.common.exceptions import nosuchelementexception selenium.webdriver.support import expected_conditions ec selenium.webdriver.common.by import selenium.webdriver.support.ui import select  def get_browser():     return webdriver.chrome()   main_page_url = "http://example.com/" basic_url = 'http://example.com/ogloszenia-kobiet.html'  def get_city_list(url) :      age_accept_button_xpath = ".//*[@id='columns']/div/div[2]/section/div/div/div/div/div/div[2]/div[2]/a[2]"     combobox_xpath = ".//*[@id='select_city']/li/form/div/button"     combobox_option_xpath = ".//*[@id='select_city']/li/form/div/div/ul/li[%s]/a/span[1]"     choose_button_xpath = ".//*[@id='select_city']/li/form/button"      pages = []      try:         browser = get_browser()         wait = webdriverwait(browser, 100)         browser.get(main_page_url)         time.sleep(2)          button_age_accept = browser.find_element_by_xpath(age_accept_button_xpath)         button_age_accept.click()         time.sleep(10)          browser.get(url)          = 2          while(true) :             try :                  button_combobox = browser.find_element_by_xpath(combobox_xpath)                 button_combobox.click()                 time.sleep(5)                  element_xpath = combobox_option_xpath %                 option_in_combobox = browser.find_element_by_xpath(element_xpath)                  actionchains = actionchains(browser)                 scrollbar = browser.find_element_by_xpath("/html/body/section/section[2]/div/div[2]/section/div/div/div/div[1]/ul/li/form/div/div/ul")                 actionchains.click_and_hold(scrollbar).perform()                 actionchains.move_by_offset(0,10+i).perform()                 actionchains.release()                  browser.execute_script("arguments[0].scrollintoview();", option_in_combobox)                 option_in_combobox.click()                  browser.execute_script("window.scrollto(0, 0);")                  button_choose = browser.find_element_by_xpath(choose_button_xpath)                 button_choose.click()                 time.sleep(5)                  pages.append(browser.current_url)                  += 1             except exception, e:                 print e                 break          browser.close()         return pages      except exception, e:         info = 'generic exception\n'         print e         return []  pages = get_city_list(basic_url) p in pages :     open('links.txt', 'a') the_file:         the_file.write(p)         the_file.write('\n') 

------------------------------------------------------------------------------------------------------------------------------------ update: ------------------------------------------------------------------------------------------------------------------------------------

for on, i'm using kubuntu 14.04. have python 2.7.11 , selenium 2.49.2. current code:

#!/bin/env/python # -*- coding: utf-8 -*-  import time selenium.webdriver.common.by import selenium.webdriver.support.wait import webdriverwait selenium import webdriver selenium.webdriver.common.action_chains import actionchains selenium.common.exceptions import nosuchelementexception selenium.webdriver.support import expected_conditions ec selenium.webdriver.common.by import selenium.webdriver.support.ui import select  # def get_browser(): #     options = webdriver.chromeoptions() #     options.add_argument("--start-maximized") #     return webdriver.chrome(chrome_options=options)   def get_browser():     return webdriver.firefox()  main_page_url = "http://example.com/" basic_url = 'http://example.com/ogloszenia-kobiet.html'  def get_city_list(url) :      age_accept_button_xpath = ".//*[@id='columns']/div/div[2]/section/div/div/div/div/div/div[2]/div[2]/a[2]"     combobox_xpath = ".//*[@id='select_city']/li/form/div/button"     combobox_option_xpath = ".//*[@id='select_city']/li/form/div/div/ul/li[%s]/a/span[1]"     choose_button_xpath = ".//*[@id='select_city']/li/form/button"      pages = []      try:         browser = get_browser()         wait = webdriverwait(browser, 100)         browser.get(main_page_url)         time.sleep(2)          button_age_accept = browser.find_element_by_xpath(age_accept_button_xpath)         button_age_accept.click()         time.sleep(10)          browser.get(url)          = 2          while(true) :             try :                  button_combobox = browser.find_element_by_xpath(combobox_xpath)                 button_combobox.click()                 time.sleep(5)                  element_xpath = combobox_option_xpath %                 option_in_combobox = browser.find_element_by_xpath(element_xpath)                 option_in_combobox.click()                  button_choose = browser.find_element_by_xpath(choose_button_xpath)                 button_choose.click()                 time.sleep(5)                  pages.append(browser.current_url)                  += 1             except exception, e:                 print e                 break          browser.close()         return pages      except exception, e:         info = 'generic exception\n'         print e         return []  pages = get_city_list(basic_url) p in pages :     open('links.txt', 'a') the_file:         the_file.write(p)         the_file.write('\n') 

for firefox, code exits @ element 'gdańsk' message: string indices must integers, means not find every element in combobox.

for chrome , windows xp, exits @ 'bielsko-biała', again, means not find every element in combobox. ...

how can solve issue?

either move element , click:

from selenium.webdriver.common.action_chains import actionchains  actions = actionchains(browser) actions.move_to_element(option_in_combobox).click().perform() 

or, scroll it's view:

browser.execute_script("arguments[0].scrollintoview();", option_in_combobox) 

or, click element via javascript:

browser.execute_script("arguments[0].click();", option_in_combobox) 

for firefox, code exits @ element 'gdańsk' message: string indices must integers, means not find every element in combobox.

there existing problem in selenium 2.49 may cause typeerror. need downgrade 2.48:

pip install selenium==2.48 

Comments