0

I'm trying to use selenium on a search box on this site: https://www.claytoncountyga.gov/government/sheriff/inmate-search

def clayton_search(last, first, middle):
    print("Clayton County Jail")
    url = "https://www.claytoncountyga.gov/government/sheriff/inmate-search"
    driver = webdriver.Chrome(chrome_options=(), executable_path="/usr/bin/chromedriver")
    driver.get(url)
    wait = WebDriverWait(driver, 30)
    wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#name")))
    driver.find_element_by_css_selector("#name").send_keys(last," ",first, " ", middle, Keys.ENTER)    
    return driver

driver = clayton_search(last, first, middle)

The site uses angularJS, and I know that on angularJS sites selenium wont see see elements unless you tell it to wait until the element is visible. Such as:

wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#name")))

But I get a timeout exception. I've tried finding the element by CSS selector, XPATH, and ID.

Even though the stack trace didn't indicate it might be hiding behind another element. I tried that too by using: driver.execute_script

I thought maybe the pop up menu from the navigator bar might be covering it, but It only appear when the cursor is over the nav bar.

Why am I not able to use wait.until(EC.visibility_of_element_located to locate the element on this AngularJS site?

1
  • 1
    element #name is inside iframe - for Selenium items in iframe are not part of page. You have to find iframe and switch_to() to this frame to find element in this iframe Commented Apr 7, 2019 at 20:48

2 Answers 2

1

There is an iframe which stopping you to access the element.You have to switch the iframe first.try below code.

def clayton_search(last, first, middle):
    print("Clayton County Jail")
    url = "https://www.claytoncountyga.gov/government/sheriff/inmate-search"
    driver = webdriver.Chrome(chrome_options=(), executable_path="/usr/bin/chromedriver")

    driver.get(url)
    wait = WebDriverWait(driver, 30)
    wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID,"Clayton County")))
    wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#name")))
    driver.find_element_by_css_selector("#name").send_keys(last," ",first, " ", middle, Keys.ENTER)
    return driver
Sign up to request clarification or add additional context in comments.

Comments

1

This page has #name in iframe and Selenium doesn't search in iframe.
You have to first switch_to.frame() and then you can search inside iframe

import selenium.webdriver

url = "https://www.claytoncountyga.gov/government/sheriff/inmate-search"
driver = selenium.webdriver.Firefox()
driver.get(url)

iframes = driver.find_elements_by_tag_name('iframe')
#print('iframes:', iframes)

driver.switch_to.frame(iframes[0])

item = driver.find_element_by_id('name')
#print('name:', item)
item.send_keys("John")

item = driver.find_element_by_name('NameSearch')
#print('name:', item)
item.click()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.