pythonseleniumacs

Selenium Python: Census ACS Data- unable to select Download button in window


I am attempting to scrape the Census website for ACS data. I have scripted the whole processes using Selenium except the very last click. I am using Python. I need to click a download button that is in a window that pops when the data is zipped and ready, but I can't seem to identify this button. It also seems that the button might change names based on when it was last run, for example, yui-gen2, yui-gen3, etc so I am thinking I might need to account for this someone. Although I normally only see yui-gen2.

Also, the tag seems to be in a "span" which might be adding to my difficulty honing in on the button I need to click.

Please help if you can shed any light on this for me.

code snippet: #Refine search results to get tables

driver.find_element_by_id("prodautocomplete").send_keys("S0101")
time.sleep(2)
driver.find_element_by_id("prodsubmit").click()
driver.implicitly_wait(100)
time.sleep(2)
driver.find_element_by_id("check_all_btn_above").click()
driver.implicitly_wait(100)
time.sleep(2)
driver.find_element_by_id("dnld_btn_above").click()
driver.implicitly_wait(100)
driver.find_element_by_id("yui-gen0-button").click()
time.sleep(10)
driver.implicitly_wait(100)
driver.find_element_by_id("yui-gen2-button").click()

enter image description here

enter image description here


Solution

  • Given the HTML you provided, you should be able to use

    driver.find_element_by_id("yui-gen2-button")
    

    I know you said you tried it but you didn't say if it works at all or what error message you are getting. If that never works, you likely have an IFRAME that you need to switch to.

    If it works sometimes but not consistently due to changing ID, you can use something like

    driver.find_element_by_xpath("//button[.='Download']")