代码之家  ›  专栏  ›  技术社区  ›  Chicken Sandwich No Pickles

Python Selenium返回键

  •  0
  • Chicken Sandwich No Pickles  · 技术社区  · 3 年前

    我在看这里的文件: https://selenium-python.readthedocs.io/getting-started.html

    在文档中,他们是这样导入库的:

    from selenium.webdriver.common import Keys
    

    当我使用密钥(大写字母“K”)时,它不起作用(与文档中的操作不同),我会收到以下错误消息:

    ImportError: cannot import name 'Keys' from 'selenium.webdriver.common
    

    当我使用它时,它是有效的:

    from selenium.webdriver.common import keys
    

    但当我使用这个代码时:

    WebElement_pw.send_keys(keys.Return)
    

    我收到以下错误消息:

    AttributeError: module 'selenium.webdriver.common.keys' has no attribute 'RETURN'
    

    在使用Python时,如何在Selenium中使用Enter键?

    1 回复  |  直到 3 年前
        1
  •  2
  •   idanz    3 年前

    我认为你应该进口

    from selenium.webdriver.common.keys import Keys
    

    参见此处的参考: Typing the Enter/Return key in Selenium (您分享的文档中也提到了这一点)