0

I have a page in which you click on date first, then region and finally province and get a link to download a file. I am trying to create a loop that goes throuth all the dates, regions and provinces, and clicks on the final link downloading the dataset. However, the date, region and province options are not menus (can't use select). The loop gets stuck on the first one and I get the error "could not be scrolled into view". I am using python and selenium. My code is as follows:

for date in dates:
xpath = "/html/body/div[4]/div[2]/div[1]/div[2]/div/div[2]/div[2]/div/div/ul/li[" + str(ele) + "]/a"
driver.find_element_by_xpath(xpath).click()
driver.find_element_by_xpath('/html/body/div[4]/div[2]/div[1]/div[2]/div/div[3]/div[2]/div/div/ul/li/a').click()
for reg in regions:
    while(True):
        xpath = "/html/body/div[4]/div[2]/div[1]/div[2]/div/div[4]/div[2]/div/div/ul/li[" + str(reg) + "]/a"
        try:    
            driver.find_element_by_xpath(xpath).click()
        except:
            print(xpath)
        for prov in providences:
            xpath = "/html/body/div[4]/div[2]/div[1]/div[2]/div/div[5]/div[2]/div/div/ul/li[" + str(prov) + "]/a"
            while(True):
                try:
                    driver.find_element_by_xpath(xpath).click()
                    #driver.find_element_by_xpath('/html/body/div[4]/div[2]/div[1]/div[2]/div/div[6]/div[1]/div/a[3]/i').click()
                finally:
                    print(xpath)

Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.