Python 如何使用selenium向hideNameInput发送密钥?

Python 如何使用selenium向hideNameInput发送密钥?,python,selenium,input,Python,Selenium,Input,下面是HTML元素,我想在spanid=“nameNoteId”中输入一些内容 send_keys()在此处不起作用,因为它是span元素。如果要更改span内容,应尝试使用execute\u script()如下所示:- not_work_elem = driver.find_element_by_id('nameNoteId') driver.execute_script("arguments[0].textContent = arguments[1]", not_work_elem, "t

下面是HTML元素,我想在span
id=“nameNoteId”
中输入一些内容

send_keys()
在此处不起作用,因为它是
span
元素。如果要更改
span
内容,应尝试使用
execute\u script()
如下所示:-

not_work_elem = driver.find_element_by_id('nameNoteId')
driver.execute_script("arguments[0].textContent = arguments[1]", not_work_elem, "test")
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

url = 'http://passport2.chaoxing.com/login?fid=1479&refer=http://i.mooc.chaoxing.com'

driver = webdriver.Firefox()
driver.get(url)

wait = WebDriverWait(driver, 10)

span = wait.until(EC.visibility_of_element_located((By.ID, "nameNoteId")))
span.click()

unameId = wait.until(EC.visibility_of_element_located((By.ID, "unameId")))
unameId.send_keys('test')

passwordId = wait.until(EC.visibility_of_element_located((By.ID, "passwordId")))
passwordId.send_keys('CNM')
已编辑:-当
在span
hideNameInput()
上单击
时,看到您的网站后,调用了函数,该函数提供了对
取消隔离
输入的关注,并隐藏了可见的
span
,因此您应该尝试以下操作:-

not_work_elem = driver.find_element_by_id('nameNoteId')
driver.execute_script("arguments[0].textContent = arguments[1]", not_work_elem, "test")
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

url = 'http://passport2.chaoxing.com/login?fid=1479&refer=http://i.mooc.chaoxing.com'

driver = webdriver.Firefox()
driver.get(url)

wait = WebDriverWait(driver, 10)

span = wait.until(EC.visibility_of_element_located((By.ID, "nameNoteId")))
span.click()

unameId = wait.until(EC.visibility_of_element_located((By.ID, "unameId")))
unameId.send_keys('test')

passwordId = wait.until(EC.visibility_of_element_located((By.ID, "passwordId")))
passwordId.send_keys('CNM')

希望对您有所帮助……:)

我不是想更改span内容。但是将键发送到输入中,然后登录网站。我该怎么做?@panda0然后你需要在你的问题中指定它。。你的问题不清楚,请提供登录表单HTML。@panda0在你想
发送密钥的地方共享你的HTML。
@panda0我得到了更新的答案…它有效:)