Need to download a file using Selenium

0 votes

I'm working on Selenium with python and I want to download a file by "click event" using selenium. Below is the code and site. Can someone plz tell me how to complete this code to download both files with name "Export Data" from above url via my code?

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox()
browser.get("http://www.drugcite.com/?q=ACTIMMUNE")

browser.close()

Thanks

Mar 29, 2018 in Selenium by Shubham
• 13,110 points
296 views

1 answer to this question.

0 votes

Pretty simple...Find the element or link using find_element_by_*, function and then call the click() method. Code is below. Note that I have also added browser profiling in my code to avoid the download dialog from popping up.

from selenium import webdriver

# To prevent download dialog
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2) # custom location
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', '/tmp')
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'text/csv')

browser = webdriver.Firefox(profile)
browser.get("http://www.drugcite.com/?q=ACTIMMUNE")

browser.find_element_by_id('exportpt').click()
browser.find_element_by_id('exporthlgt').click()
answered Mar 29, 2018 by nsv999
• 5,050 points

Related Questions In Selenium

+1 vote
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Selenium XPath error:- Element not found

The reason for Element not found exception ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,050 points
1,935 views
+2 votes
2 answers

How can I press ENTER key with the execute_script in selenium python?

The below code containing Keys.ENTER might just ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,050 points
4,985 views
0 votes
1 answer

I tried to open a new website when a new tab is opened using Selenium Webdriver

Try this code: ArrayList<String> tabs = new ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,050 points
677 views
0 votes
1 answer