Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99028

How to click a button with Selenium chromedriver in Python

$
0
0

Hi Guys (sorry in advanced for my english), I want to click a button in order to download a file from this page https://myterna.terna.it/SunSet/Public/Pubblicazioni?filter.IdSezione=585AF7EFCA196EBBE0532B889B0A6372 . This is my simple code:

download_dir = 'C:/Users/Francesco.Borri/Desktop/Sunset'

options = webdriver.ChromeOptions()
prefs = {'download.default_directory' : download_dir}
options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(options=options)
driver.get('https://myterna.terna.it/SunSet/Public/Pubblicazioni?filter.IdSezione=585AF7EFCA196EBBE0532B889B0A6372')

container1 = driver.find_element_by_class_name("row") #Until this class is OK
container2 = driver.find_element_by_class_name("col-sm-12 table-wrapper") # From this class NOPE

#button = container.find_element_by_class_name(CLASS_OF_THE_BUTTON)
#button.click()

The code opens the page correctly, but It's not able to find all the classes I'm looking for (in which inside one of them there is my precious button). I studied the html page source and I found that the classes initially missing are created from a script (screenshot below) when the page is loaded. I'm not familiar with Javascript and Ajax. Is there a way to find and to click my precious button?

script that generates the classes

Once the button is clicked a "post" request is sent to a link (https://myterna.terna.it/SunSet/Public/Pubblicazioni/ExportDetails) with a bunch of information (Titolo,Id,ExtKey,...) and my file is finally downloaded. Is there a way to only press the button without retrieving all these infos (Titolo,Id,ExtKey,...)? . post method


Viewing all articles
Browse latest Browse all 99028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>