python 中的 selenium 发送密钥不起作用
sendkeys of selenium in python dose not work
我有这个代码:
from selenium import webdriver
#open Firefox
driver=webdriver.Firefox()
#open arbitrary ur
url="https://www.scopus.com/search/form.uri?display=basic"
driver.get(url)
#click on input element for writing special word
search=driver.find_element_by_xpath("""//*[@id="txtBoxSearch"]/label""")
search.click()
driver.implicitly_wait(5)
#write your special word
search.send_keys("internet of things")
driver.implicitly_wait(5)
search.submit()
错误堆栈跟踪:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: Element <label class="inputTextLabel activeInputLabel"> is not reachable by keyboard
打开了url并且识别了x-path,但是send_keys不起作用。我该怎么办?
label
节点只是一个 "name" 的输入字段,您不能向该元素发送键。您需要改为处理文本 input
节点。
假设 HTML 看起来像
<div id='txtBoxSearch'>
<label>Search</label>
<input type='text'>
</div>
你可以试试
search = driver.find_element_by_xpath("""//*[@id="txtBoxSearch"]/input[@type="text"]""")
我有这个代码:
from selenium import webdriver
#open Firefox
driver=webdriver.Firefox()
#open arbitrary ur
url="https://www.scopus.com/search/form.uri?display=basic"
driver.get(url)
#click on input element for writing special word
search=driver.find_element_by_xpath("""//*[@id="txtBoxSearch"]/label""")
search.click()
driver.implicitly_wait(5)
#write your special word
search.send_keys("internet of things")
driver.implicitly_wait(5)
search.submit()
错误堆栈跟踪:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: Element <label class="inputTextLabel activeInputLabel"> is not reachable by keyboard
打开了url并且识别了x-path,但是send_keys不起作用。我该怎么办?
label
节点只是一个 "name" 的输入字段,您不能向该元素发送键。您需要改为处理文本 input
节点。
假设 HTML 看起来像
<div id='txtBoxSearch'>
<label>Search</label>
<input type='text'>
</div>
你可以试试
search = driver.find_element_by_xpath("""//*[@id="txtBoxSearch"]/input[@type="text"]""")