如何给输入框赋值
来源:12-7 页面内容的查找和定位,实现点击操作和跳转访问(1)

慕标5054045
2024-02-26
学习课程后,想扩展一下功能,即自动为某个文本输入框赋值,代码如下
from selenium import webdriver
from selenium.webdriver.common.by import By
webie = webdriver.Chrome()
webie.get(“https://访问的网站域名”)
webie.find_element(By.ID,‘userid’).send_keys(‘test123456’)
执行后出现错误
出错信息如下:
NoSuchElementException Traceback (most recent call last)
Cell In[5], line 1
----> 1 webie.find_element(By.ID,‘userid’).send_keys(‘test123456’)
html文件部分源码如下(整个html文件中,id为userid只找到一个):
写回答
1回答
-
先找找iframe。
如果有,那就是页面嵌套页面。selenium操作浏览器,只能查看当前页面,页面中的页面,需要手动找到并切换。
新旧版本的selenium,函数代码是不完全一样的,用智能提示多看看。
022024-02-27
相似问题