Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AttributeError: type object 'By' has no attribute 'id' Selenium

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')

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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:

enter image description here

Imports:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading