我正在尝试使用Selenium WebDriver在网站上输入ID和密码,但是我的代码不起作用。似乎找不到元素。
我检查了HTML代码并找到了值。
这是我的Python代码
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('ㅁ')
这是HTML代码
input type="text" style="color:#000000; height: 16px; width:138px;ime-mode:inactive" name="id" autocomplete="off" tabindex="1" placeholder="아이디를 입력하십시오." value=""
答案 0 :(得分:2)
有嵌套框架需要协商
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")
您可以将等待条件用于帧:
WebDriverWait(driver, 5).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"[type=password]")))