Python 如何使用动态@id将文本发送到输入字段

Python 如何使用动态@id将文本发送到输入字段,python,selenium,automation,Python,Selenium,Automation,我试着到处寻找解决方案,但没有找到综合答案。我试图填写动态@id表单,并将我的代码逻辑应用到我的测试站点和udemy上,但似乎不起作用 driver.get('https://www.udemy.com/') #search= driver.find_element_by_xpath('//*[contains(@id,"-search-form-autocomplete--3")') s = WebDriverWait(driver, 10).until(EC.presen

我试着到处寻找解决方案,但没有找到综合答案。我试图填写动态
@id
表单,并将我的代码逻辑应用到我的测试站点和udemy上,但似乎不起作用

driver.get('https://www.udemy.com/')
#search= driver.find_element_by_xpath('//*[contains(@id,"-search-form-autocomplete--3")')
s = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[contains(@id,"-search-form-autocomplete--3")')))
s.send_keys("robotics")

您是否将selenium.webdriver.common.keys中的
导入密钥
放入代码中?

xpath未正确关闭关闭
]
丢失,因此可能是例外。另一件事是请添加必要的导入

当我修复xpath时,您的代码确实对我起了作用-

修正后的代码-

driver = webdriver.Chrome()
driver.get('https://www.udemy.com/')
#search= driver.find_element_by_xpath('//*[contains(@id,"-search-form-autocomplete--3")')
s = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[contains(@id,"-search-form-autocomplete--3")]')))
s.send_keys("robotics")
需要进口-

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
输出-


它抛出了什么错误?你能解释一下你得到的错误吗?哦,天哪,该死的语法错误..-非常感谢。