Michaella
Michaella

Reputation: 55

Cannot find elements when scraping website with python and selenium

I would like to map color HSB values to English color names and Hue names. One resource I have found is https://www.color-blindness.com/color-name-hue/ and I am using Selenium to scrape it. It seems though that I cannot find the elements I am interested in. This is my attemp:

import selenium
from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://www.color-blindness.com/color-name-hue/')

driver.implicitly_wait(60)

driver.find_element_by_css_selector("input#cp1_Hue")

Some other attempts:

driver.find_element_by_id("cp1_Hue")

I keep getting this error message: NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"input#cp1_Hue"} (Session info: chrome=89.0.4389.82)

Has anyone faced the same issue?

Thanks in advance!

Upvotes: 0

Views: 106

Answers (1)

Vova
Vova

Reputation: 3537

There's Iframe element, what doesn't allow to interact with elements inside it.

  1. You should switch on it
  2. Interact with elements what you're looking for

try this:

driver = webdriver.Chrome()
driver.get('https://www.color-blindness.com/color-name-hue/')

driver.implicitly_wait(5)

driver.switch_to.frame(driver.find_element(By.TAG_NAME, 'iframe'))

input = driver.find_element(By.CSS_SELECTOR, "input#cp1_Hue")
input.send_keys(10)

driver.quit()

Upvotes: 1

Related Questions