gpt4 book ai didi

python - 如何使用 selenium 和 python 将文本插入输入标签

转载 作者:太空宇宙 更新时间:2023-11-04 02:59:06 25 4
gpt4 key购买 nike

我能够通过 this 所在的类名找到元素,但我不确定如何选择它本身并向它发送文本。

当前代码:

editor = browser.find_element_by_class_name('editor')
editor.send_keys('text')

我要选择的元素:

<input type="text" tabindex="103" placeholder="" style="width: 444px;">

错误:

File "C:\Python35\lib\site-packages\selenium\webdriver\remote\webelement.py", line 347, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': keys_to_typing(value)})
File "C:\Python35\lib\site-packages\selenium\webdriver\remote\webelement.py", line 494, in _execute
return self._parent.execute(command, params)
File "C:\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python35\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element
(Session info: chrome=55.0.2883.87)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.14393 x86_64)

最佳答案

您尝试选择的元素没有类名。尝试

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

editor = WebDriverWait(browser, 10).until(EC.visibility_of_element_located((By.XPATH, '//input[@type="text"][@tabindex="103"]')))
editor.send_keys('text')

关于python - 如何使用 selenium 和 python 将文本插入输入标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41537618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com