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

前端 未结 6 897
甜味超标
甜味超标 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:24

    The username and password fields are within an frame, so you have to:

    • Induce WebDriverWait for the desired frame to be available and switch to it.
    • Induce WebDriverWait for the desired element to be clickable.
    • You can use the following solution:

      from selenium import webdriver
      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.support import expected_conditions as EC
      from selenium.webdriver.common.by import By
      
      driver = webdriver.Firefox(executable_path=r'C:\\Utility\\BrowserDrivers\\geckodriver.exe')
      driver.get("http://sugang.korea.ac.kr")
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"firstF")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.input_login[name='id']"))).send_keys('abc')
      driver.find_element_by_css_selector("input.input_login[name='pw']").send_keys("cdef")
      
    • Browser Snapshot:

提交回复
热议问题