无法使用selenium和python定位文本输入元素

2024-06-01 08:04:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Selenium和Python在网页(https://www.fimea.fi/web/en/databases_and_registeries/spcs/human_medicinal_products)上查找一个元素,我希望找到医药产品名称的第一个文本输入

我得到这个错误:

Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@name='nimi'][@type='text']"}

我目前正在使用以下代码:

clear_button = driver.find_element_by_xpath("//input[@name='nimi'][@type='text']")

我不熟悉Python和Selenium。请帮我解决这个问题


Tags: textnamehttpsweb网页inputwwwtype
2条回答

您要查找的字段位于iframe内。 您需要首先识别并切换到该iframe

iframe=driver.switch_to.frame('_com_liferay_iframe_web_portlet_IFramePortlet_INSTANCE_1UG85fOFT8Za_iframe')
input_field = driver.find_element_by_xpath("//input[@name='nimi']")

无法定位元素的原因是输入框被一个框架隐藏。也许您应该使用switch_to.frame()来切换到它。 F12 screenshot

相关问题 更多 >