python中的硒:NoSuchElementException:消息:没有这样的元素:无法定位元素 [英] selenium in python : NoSuchElementException: Message: no such element: Unable to locate element

查看:36
本文介绍了python中的硒:NoSuchElementException:消息:没有这样的元素:无法定位元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在第一个 id 块中键入 'abc',在第二个密码块中键入 'cdef'.但是,底部的错误代码出现了.

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 import webdriver
driver.get('http://sugang.korea.ac.kr')

添加了隐式等待以防止代码在页面完全加载之前执行.

Added implicitly wait to prevent the code from executing before the page fully loads.

driver.implicitly_wait(30)

添加用户名和密码的代码如下

Code for adding username and password is as below

driver.find_element_by_name('id').send_keys('abc')driver.find_element_by_name('pw').send_keys('cdef')

但低于错误

NoSuchElementException:消息:没有这样的元素:无法定位元素:{"method":"id","selector":"id"}

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"id"}

请.帮帮我^^

推荐答案

usernamepassword 字段位于 frame 内,因此您必须:

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

  • 诱导 WebDriverWait 使所需的框架可用并切换到它.
  • 诱导 WebDriverWait 使所需的元素可点击.
  • 您可以使用以下解决方案:

  • 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:

    这篇关于python中的硒:NoSuchElementException:消息:没有这样的元素:无法定位元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆