selenium in python : NoSuchElementException: Message: no such element: Unable to locate element

前端 未结 6 903
甜味超标
甜味超标 2020-11-22 08:41

I tried typing \'abc\' in the first block of id and \'cdef\' in the second block of password. However, the error code at the bottom comes up.

from selenium          


        
6条回答
  •  不要未来只要你来
    2020-11-22 09:26

    It is in a frame which you need to switch to first. Also, use ids where possible as they are faster.

    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://sugang.korea.ac.kr"
    driver = webdriver.Chrome()
    driver.get(url)
    WebDriverWait(driver,5).until(EC.visibility_of_element_located((By.CSS_SELECTOR,'[name=firstF]')))
    driver.switch_to.frame(driver.find_element_by_css_selector('[name=firstF]'))
    WebDriverWait(driver,5).until(EC.visibility_of_element_located((By.ID,'id'))).send_keys('abc')
    driver.find_element_by_id('pw').send_keys('def')
    driver.find_element_by_id('loginButton').click()
    

提交回复
热议问题