0

I am trying to click the GetData button and get the output but this does not work for me. Not sure how can i do this.

Code changes below:-

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time

chromeOptions=Options()
chromeOptions.add_argument("--ignore-certificate-errors")
chromeOptions.add_argument("--incognito")
chromeOptions.add_argument("--kiosk")
chromeOptions.add_argument("--window-size=1366,768")

driver =webdriver.Chrome(executable_path=r"C:/Users/lenovo/Downloads/chromedriver_win32/chromedriver.exe",options=chromeOptions)
driver.get("https://www1.nseindia.com/products/content/equities/equities/eq_security.htm")
period_ele=driver.find_element_by_name("dateRange")
time.sleep(3)
period_ele.send_keys(Keys.DOWN)
period_ele.send_keys(Keys.DOWN)
period_ele.send_keys(Keys.DOWN)

period_ele=driver.find_element_by_name("symbol")
time.sleep(3)
period_ele.send_keys("INFY")
driver.find_element_by_css_selector('p.getdata-button>onclick').click()

Want to click on the button

Invictus
  • 4,028
  • 10
  • 50
  • 80

1 Answers1

0

The selector p.getdata-button>onclick will try to find a p element with a class name of getdata-button.

The second part (>onclick) looks for a direct descendant onclick element.

In short, the selector would match HTML like this:

<p class="getdata-button"><onclick/></p>

To click the button you wan't the input element. This has an id attribute that we can use, and the code becomes:

driver.find_element_by_css_selector('#submitMe').click()

Or

driver.find_element_by_id('submitMe').click()

If you need to find the CSS selector of an element you can let Chrome find it for you by right clicking on the element in the DOM explorer and selecting Copy > Copy selector.

Copy selector in Chrome

Update

Based on the linked answers and my own testing the button is being clicked, but there is some sort of detection in place that prevents the data from being loaded from the server.

I will suggest you look into the linked answers to see if they can help you with this new problem.

TAS
  • 2,039
  • 12
  • 17
  • I get error "Message: element not interactable (Session info: chrome=84.0.4147.105)" using both the option. – Invictus Aug 08 '20 at 15:32
  • Also after you showed me how to get selector i tried below. driver.find_element_by_xpath("//*[@id='get']").click() it does not give me any error but screen does not get refreshed.I was expecting the webpage to get refresh and give me output. – Invictus Aug 08 '20 at 15:38
  • @Invictus I tried running the script and using find_element_by_id('get') and it seems to hang. May be some script running, but I don't have time to look into i anymore tonight. Will try to look at it tomorrow. – TAS Aug 08 '20 at 16:04