Reputation: 1622
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 :')
Upvotes: 0
Views: 171
Reputation: 12672
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:
Upvotes: 1