pythonselenium-webdriverbuttonclick

Download by clicking button on webpage


import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys


options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
options.add_experimental_option('excludeSwitches', \['enable-logging'\])

s = Service('C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)

driver.get("https://chartink.com/stocks/nifty.html")

driver.maximize_window()
time.sleep(10)

element1 = driver.find_element(By.ID,'paint')
driver.execute_script("arguments\[0\].click();", element1);[tag:tag-name]

--- ID ="paint"?

On site there is button "SAVE IMAGE". Once we click it charts are downloaded automatically. I am trying to simulate click () but it is not working. I might be selecting wrong id or may be I using wrong interaction with element?

Can someone help me?


Solution

  • Have you considered using Selenium Helium library? https://selenium-python-helium.readthedocs.io/en/latest/api.html

    It makes it super easy to automate the browser without having to deal with the technical complexities. It is very user friendly and takes care of that behind the scenes. You just have to tell it which button to click in 'plain English' Examples:

    click("SAVE IMAGE")
    
    
    click("Paint")
    click("Sign in")
    click(Button("OK"))
    doubleclick(Image("Directories"))
    

    More details can be found in the documentation. Hope that helps!