【问题标题】:I cant seem to be able to type in to the input box我似乎无法在输入框中输入
【发布时间】:2021-05-16 22:57:58
【问题描述】:

我正在尝试使用 selenium 在以下网站上的输入框中输入内容。

https://www.telia.no/kundeservice/kontakt-oss/kontaktskjema/

我正在使用这个 Xpath 来寻址输入框:

//*[@id="c4548208-26f1-4f89-aa7e-ceef0f60de81"]

我尝试使用 xpath、类名、id 以及 time.sleep,但我仍然收到他的错误消息:

selenium.common.exceptions.NoSuchElementException:
    Message: no such element: Unable to locate element:
    {"method":"xpath","selector":"//*[@id="96509b70-d1d6-4bbb-82ef-516e80cebc56"]"}

如何在文本框中输入内容?

【问题讨论】:

标签: python selenium xpath input text


【解决方案1】:

我注意到您的问题和您显示的错误消息表明两个不同的 id,据说是同一个元素。所以可能是网站每次下载页面时都会生成一个新的 id,这可以解释为什么你的代码永远找不到它。

您可以尝试使用 id 以外的属性或通过其父元素来访问元素。

【讨论】:

    【解决方案2】:
    from selenium import webdriver
    
    driver = webdriver.Chrome()
    driver.get("https://www.telia.no/kundeservice/kontakt-oss/kontaktskjema/")
    # click accept cookies
    driver.find_element_by_xpath('//*[@id="cookie-consent-form-container"]/div/div/div/button[1]').click()
    
    #click search icon
    driver.find_element_by_xpath("/html/body/nav/div/div[2]/div/div/button/div").click()
    
    #input box
    driver.find_element_by_xpath("/html/body/nav/div/div[2]/div/div/div/form/label/div/input").send_keys("abcd\n")
    

    【讨论】:

      猜你喜欢
      • 2020-03-31
      • 1970-01-01
      • 1970-01-01
      • 2015-10-19
      • 2019-09-26
      • 1970-01-01
      • 2014-04-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多