如何将文本发送到输入字段

How to send text to input field

driver.get("https://beta.stress.pw/login")
enter_searchbar.element = driver.find_element_by_xpath=("/html/body/div[1]/div/div[2]/form/div/div[2]/input[1]")
enter_searchbar.send_keys("itartinas1")

我得到的错误:

Exception has occurred: StaleElementReferenceException Message: stale element reference: element is not attached to the page document
(Session info: chrome=86.0.4240.198)

你的语法

enter_searchbar.element = driver.find_element_by_xpath=(<XPATH>) 

没有按照您的预期去做 - 它只是将新的 属性 element 添加到现有的 enter_searchbar 对象并将其设置为字符串 "/html/body..."

使用正确的语法查找元素,并尽量避免使用自动生成的 XPath 定位器:

driver.get("https://beta.stress.pw/login")
enter_searchbar = driver.find_element_by_name("login-username")
enter_searchbar.send_keys("itartinas1")