Kerry Lee
Kerry Lee

Reputation: 57

Unable to find element in selenium

I'm trying to enter an ID and password on a website using Selenium WebDriver but my code doesn't work. It seems that it can't find an element.

I checked the HTML code and found the value.

This is my Python code

from selenium import webdriver

driver=webdriver.Chrome('C:\Chrome_Driver\chromedriver.exe')
driver.get('http://hisnet.handong.edu/')
sleep(0.5)
driver.find_element_by_name('id').send_keys('ㅁ')  
sleep(0.5)
driver.find_element_by_name('password').send_keys('ㅁ')

and this is the HTML code

input type="text" style="color:#000000; height: 16px; width:138px;ime-mode:inactive" name="id" autocomplete="off" tabindex="1" placeholder="아이디를 입력하십시오." value=""

Upvotes: 1

Views: 87

Answers (1)

QHarr
QHarr

Reputation: 84465

There are nested frames to negotiate

from selenium import webdriver
#from selenium.webdriver.common.by import By
#from selenium.webdriver.support.ui import WebDriverWait
#from selenium.webdriver.support import expected_conditions as EC

url = 'http://hisnet.handong.edu/'
driver = webdriver.Chrome()
driver.get(url)
driver.switch_to.frame(driver.find_element_by_css_selector("[name=MainFrame]"))
driver.switch_to.frame(driver.find_element_by_css_selector("[name=MainFrame]"))
driver.find_element_by_css_selector("[name=id").send_keys("banana")
driver.find_element_by_css_selector("[type=password]").send_keys("orange")

You could use wait condition for frame:

 WebDriverWait(driver, 5).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"[type=password]")))

Upvotes: 2

Related Questions