Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am trying to fill dropdown form using Selenium. I am trying select the dropdown element by its ID but getting this error:
AttributeError: type object 'By' has no attribute 'id'
I am getting this error for this line:
element = driver.find_element(By.id('State'))
from lib2to3.pgen2 import driver
from sre_parse import State
from tkinter.tix import Select
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
import time
# web = webdriver.Chrome(ChromeDriverManager().install())
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://ssg2021.in/citizenfeedback")
time.sleep(2)
element = driver.find_element(By.id('State'))
drp = Select(element)
drp.select_by_visible_text('Chhattisgarh')
wait=WebDriverWait(driver,30)
driver.get("https://ssg2021.in/citizenfeedback")
element = wait.until(EC.presence_of_element_located((By.ID,"State")))
drp = Select(element)
drp.select_by_visible_text('Chhattisgarh')
Just wait for presence of element and then select by text.
Outputs:
Imports:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC