【问题标题】:Unable to locate text input element using selenium and python无法使用 selenium 和 python 定位文本输入元素
【发布时间】:2020-05-28 05:15:50
【问题描述】:

我正在尝试使用 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 的新手。请帮我解决这个问题。

【问题讨论】:

  • 请添加您要查找的元素的html。

标签: python selenium xpath selenium-chromedriver


【解决方案1】:

找不到元素的原因是输入框被边框隐藏了。也许您应该使用switch_to.frame() 切换到它。 F12 screenshot

【讨论】:

    【解决方案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']")
    

    【讨论】:

    • 谢谢,我现在可以找到它了。
    猜你喜欢
    • 2020-12-26
    • 1970-01-01
    • 1970-01-01
    • 2020-01-26
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-29
    相关资源
    最近更新 更多