吃饭睡觉 发表于 2019-12-14 20:24:57

【求助】定位163邮箱用户名输入框失败!!!

哪位大神有空,帮忙看看问题出在哪里,谢谢啦
定位class=u-input box的div也没有成功

代码:

#!usr/bin/python
# -*- coding:utf-8 -*-
from selenium import webdriver

driver = webdriver.Firefox()
driver.get('https://mail.163.com/')
# 默认显示二维码登录,点右上角切换到用户名密码登录
driver.find_element_by_id("lbNormal").click()
# 通过Xpath定位到输入框
driver.find_element_by_xpath("//input[@name='email']")
input('Press any key to close firefox')
driver.quit()


报错信息:

C:\ProgramData\Anaconda3\python.exe D:/PythonScript/Project1/venv/Scripts/lianxi.py
Traceback (most recent call last):
File "D:/PythonScript/Project1/venv/Scripts/lianxi.py", line 10, in <module>
    driver.find_element_by_xpath("//input[@name='email']")
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
    'value': value})['value']
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
File "C:\ProgramData\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //input[@name='email']



applepen 发表于 2019-12-16 08:17:39

1.看一下此窗体时候有iframe层。如果有就切到该层进行操作。
2.在点击之后加一些时间等待。
3.用input标签下边的span试试。

jj52314 发表于 2019-12-16 09:11:56

本帖最后由 jj52314 于 2019-12-16 09:15 编辑

因为这个登录框是在一个iframe内的,需要先切换到这个iframe。所以在find输入框之前添加这两行
frameLogin = driver.find_element_by_xpath('//*[@frameborder="0"]')
driver.switch_to.frame(frameLogin)
页: [1]
查看完整版本: 【求助】定位163邮箱用户名输入框失败!!!