【问题标题】:Not able to insert text in textbox using Selenium (using firefox)无法使用 Selenium 在文本框中插入文本(使用 firefox)
【发布时间】:2018-10-06 19:25:30
【问题描述】:

我正在尝试将文本插入文本框。当我检查文本框时,我发现它们不是文本框的标识符,所以我使用了 xpath。

On inspecting the textbox

textbox = driver.find_elements_by_xpath("/html/body/main/article/div/div/div[3]/div/div[1]/div/div/form/div[1]/div/div/div/div[1]/textarea")
textbox.click()
textbox.send_keys("convert")

但是会报错

"AttributeError: 'list' 对象没有属性 'click'".

我试图找出文本的写入位置,它是在 Code-line 类中编写的。 Code gets written here

我不明白这里实际发生了什么,因为我没有看到任何没有任何标识符的文本框。

如何识别文本框并将文本插入其中?

【问题讨论】:

    标签: javascript python selenium automation


    【解决方案1】:

    您应该使用driver.find_element_by_xpath 而不是driver.find_elements_by_xpath

    driver.find_element_by_xpath 返回单个 web 元素,因此您可以执行clicksendkeys 之类的操作

    driver.find_elements_by_xpath 返回网页元素列表 所以需要迭代列表来逐个提取网页元素

    【讨论】:

    • 当我这样做时,它会引发另一个异常。 selenium.common.exceptions.ElementNotInteractableException:消息:元素
    • 当前错误ElementNotInteractableException 与问题中的错误"AttributeError: 'list' object has no attribute 'click'" 不同。您能否AcceptAnswer 并针对您的新要求提出新问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 2018-09-27
    • 1970-01-01
    • 2017-04-12
    • 2021-10-11
    相关资源
    最近更新 更多