Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python selenium无法定位username元素_Python_Selenium - Fatal编程技术网

Python selenium无法定位username元素

Python selenium无法定位username元素,python,selenium,Python,Selenium,我正在尝试使用Python和Selenium为我的本地图书馆网站()创建一个自动登录系统。但是,我的脚本找不到用户名框 网站中用户名框的HTML如下所示 这是我用来找到它的代码 username = browser.find_element_by_id('j_username') username.send_keys(u) 但是,我得到以下错误: selenium.common.exceptions.NoSuchElementException: Message: no such eleme

我正在尝试使用Python和Selenium为我的本地图书馆网站()创建一个自动登录系统。但是,我的脚本找不到用户名框

网站中用户名框的HTML如下所示

这是我用来找到它的代码

username = browser.find_element_by_id('j_username')
username.send_keys(u)
但是,我得到以下错误:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"j_username"}

我应该使用不同的功能吗?还是我使用find_element_by_id()错误?提前感谢。

您也可以不使用iframe登录该网站

browser.get(“http://mcls.ent.sirsi.net/client/en_US/login")

浏览器。通过id(“j\u用户名”)查找元素。发送密钥(u)
登录表单位于框架上。你必须切换到帧

browser.get("http://mcls.ent.sirsi.net/client/en_US/mclweb")
browser.find_element_by_class_name('loginLink').click()
time.sleep(5)
browser.switch_to.frame(1) //login iframe is the second frame in the page
time.sleep(5)
browser.find_element_by_id('j_username').send_keys(u)
另一种方法,如果您不想切换到帧:

browser.get("http://mcls.ent.sirsi.net/client/en_US/mclweb/search/patronlogin")
browser.find_element_by_id('j_username').send_keys(u)

您要查找的
输入
位于IFRAME内。您需要切换到它,然后才能访问用户名字段。@TarunPrakash如果有帮助,请通知我