我正在尝试使用sendKeys()函数,但是我一直收到错误消息"Element not interactable“,我不知道为什么。当我使用pyautogui函数press()而不是sendKeys()时,它工作得很好
《守则》
import pyautogui
import time
print('started')
web=webdriver.Chrome()
web.get('https://pt.symbolab.com/')
time.sleep(10)
expression = '2+2'
formXpath = web.find_element_by_id('main-input')
formXpath.click()
time.sleep(10)
formXpath.send_keys(expression)
##pyautogui.press('2') this line works
input = input('Quer parar o programa?')
if input=='s':
exit()
发布于 2021-02-26 04:29:43
下面的代码可以正常工作。我使用webdriverwait等待主输入出现,与您的代码相比的主要区别是,我使用ID main-input
单击跨度,但send_keys
事件被发送到作为孙子的textarea子对象。你不能通过send_keys连接到span
标签。
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
driver_path = '<YOUR DRIVER PATH>'
driver = webdriver.Chrome(driver_path)
expression = '2+2'
driver.get('https://pt.symbolab.com/')
span = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "main-input"))
)
textarea = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//*[@id=\"main-input\"]/span[1]/textarea"))
)
span.click()
textarea.send_keys(expression)
https://stackoverflow.com/questions/66375791
复制相似问题