0

I am looking forward to filling in the form at this website. In the very first step, I am unable to find out the element corresponding to the first dropdown menu of 'State Name :'. Any help will be appreciated. Here is what I have tried so far:

import os
from selenium import webdriver
driver_path = r'pathtochromedriver\chromedriver.exe'
driver = webdriver.Chrome(driver_path)
driver.get('https://app.cpcbccr.com/ccr/#/caaqm-dashboard-all/caaqm-landing/data')
elem = driver.find_element_by_name('State Name :')
Vinod Kumar
  • 1,383
  • 1
  • 12
  • 26

1 Answers1

1

You got this element in a wrong way.Selenium couldn't find it.

If you just want to get the elements in first dropdown, try code below:

import time
from selenium import webdriver
import os

driver_path = r'pathtochromedriver\chromedriver.exe'
driver = webdriver.Chrome(driver_path)
driver.get('https://app.cpcbccr.com/ccr/#/caaqm-dashboard-all/caaqm-landing/data')
time.sleep(8) # sleep some time for waiting(It depends on your internet speed).You could also try WebDriverWait or implicitly_wait

elem = driver.find_elements_by_class_name('toggle')[0] # get the first dropdown button
elem.click() # click it.
 
dropdown = driver.find_element_by_css_selector('.options')
for state in dropdown.find_elements_by_css_selector('li'):
    print(state.text) # get the text in dropdown menu

And this gave me:

Andhra Pradesh
Assam
Bihar
Chandigarh
Delhi
Gujarat
Haryana
Jharkhand
Karnataka
Kerala
Madhya Pradesh
Maharashtra
Meghalaya
Mizoram
Nagaland
Odisha
Punjab
Rajasthan
Tamil Nadu
Telangana
Uttar Pradesh
West Bengal

Press F12 on this page,and:

enter image description here

jizhihaoSAMA
  • 12,336
  • 9
  • 27
  • 49
  • Thanks a lot for the answer. Indeed it works, thanks for that. Can you be so nice to tell, how did you find out the class names "toggle", "options" and "li". This would help me to navigate through the page further. – Vinod Kumar Oct 30 '20 at 13:47
  • @VinodKumar I add an example about it in Chrome. – jizhihaoSAMA Oct 30 '20 at 13:55
  • Another question related to the same page? I could not locate element for "Select parameter". This is within span. how do I select "select all within it?" – Vinod Kumar Oct 30 '20 at 14:44
  • @VinodKumar Try xpath.In my PC, `driver.find_element_by_xpath("//*[text()='Select All']").click()` works fine. – jizhihaoSAMA Oct 30 '20 at 14:51
  • Great! xpath works well. Prior to "Select all" i needed to click "Select Parameter". Thanks again. – Vinod Kumar Oct 30 '20 at 15:08
  • can you please check one further issue with the calendar on the same page. The question is posted at https://stackoverflow.com/questions/64660455/selenium-calendar-picker-i-can-click-manually-but-selenium-cant-click – Vinod Kumar Nov 03 '20 at 13:17