I am trying to extract tables from dropdown menus but I keep on getting an exception error that the element is not attached to the document in the last loop. I think it is to do with the fact that the page refreshes when clicking on submit.
My code:
###Purpose: To retrieve gp election data
import time
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
## wesbsite details
driver = webdriver.Chrome(executable_path = '/usr/local/bin/chromedriver')
driver.get('http://wbsec.gov.in/results/panchayat_election_detailed_result?election_year=2013')
driver.maximize_window()
## dropdown menu
elements=driver.find_elements_by_tag_name("input")
for element in elements:
if element.get_attribute("value")=="PANCHAYAT SAMITY":
element.click()
districts = Select(driver.find_element_by_id('zilla_parishad'))
for district in districts.options:
district.click()
time.sleep(1)
blocks=Select(driver.find_element_by_id('panchayat_samity'))
for block in blocks.options:
block.click()
time.sleep(1)
poles=Select(driver.find_element_by_id('election_date'))
for pole in poles.options:
pole.click()
time.sleep(1)
test = driver.find_element_by_xpath("//input[@type='submit']").click()
time.sleep(5)
The error occurs in this line:
driver.find_element_by_xpath("//input[@type='submit']").click()
I think the issue is that the page does not have enough time to load. I have tried to increase the sleep time as well as use WebDriverWait
but I get the same error each time.