python selenium 没有要发送键的元素

发布于 2025-01-15 17:55:56 字数 1266 浏览 0 评论 0原文

本人刚开始学习selenium,如有错误还请谅解。 谢谢:)

我想爬行一个网站,可以通过硒创建一个名为“tistory”的博客。

为了创建文章,您必须选择默认模式、markdown 模式或 html 模式之一。

基本模式是可以的。 在此处输入图像描述

iframe=driver.find_element_by_css_selector('iframe')
driver.switch_to.frame(iframe)
driver.find_element_by_id('tinymce').send_keys("test text")

但我想做的是html模式,所以我创建了一个代码,可以通过selenium以html模式自动写入。 在此处输入图像描述

text_box = driver.find_element_by_css_selector("#html-editor-container > div.mce-edit-area > div > div > div:nth-child(1) > textarea")
text_box.send_keys("test text")

another element textarea

text_box = driver.find_element_by_css_selector("div.ReactCodemirror>textarea")
text_box.send_keys("test text")

当我尝试运行它时出现错误。

selenium.common.exceptions.ElementNotInteractableException: Message: element (Session info: chrome=99.0.4844.74)

关于该错误,我认为 textarea 元素是用于写入文本的不正确元素,但我不知道什么是正确的元素。

这是html模式的html。 在此处输入图像描述

这个问题已经困扰我三天了。 请解决这个问题。我求求你。

I just started studying selenium, so please understand if there is any mistake.
Thankyou :)

I would like to crawling a site where can create a blog called 'tistory' through selenium.

In order to create an article, you must choose one of the default mode, markdown mode, or html mode.

Basic mode is possible.
enter image description here

iframe=driver.find_element_by_css_selector('iframe')
driver.switch_to.frame(iframe)
driver.find_element_by_id('tinymce').send_keys("test text")

But I want to do is html mode, so I created a code that can automatically write through selenium in html mode.
enter image description here

text_box = driver.find_element_by_css_selector("#html-editor-container > div.mce-edit-area > div > div > div:nth-child(1) > textarea")
text_box.send_keys("test text")

another element textarea

text_box = driver.find_element_by_css_selector("div.ReactCodemirror>textarea")
text_box.send_keys("test text")

An error appears when I try to run it.

selenium.common.exceptions.ElementNotInteractableException: Message: element (Session info: chrome=99.0.4844.74)

Regarding the error, I think the textarea element is an incorrect element for writing text, but I don't know what is the correct element.

this is html mode html.
enter image description here

This problem has been bothering me for three days.
Please solve this problem. I beg you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℡寂寞咖啡 2025-01-22 17:55:56

HTML 模式中,您没有看到iframe

或者

由于您在基本模式下切换到iframe,因此您是否切换到默认内容

要解决

selenium.common.exceptions.ElementNotInteractableException: Message: element (Session info: chrome=99.0.4844.74)

您应该像下面这样调试代码:

  1. 确保浏览器使用全屏启动

    driver.maximize_window()
    
  2. 使用

    Use ActionChains

    ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.visibility_of_element_ located((By.CSS_SELECTOR, "div.ReactCodemirror>textarea")))).send_keys('这里有东西') 。履行()
    
  3. 使用execute_script

    text_area = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.ReactCodemirror>textarea")))
    driver.execute_script("arguments[0].setAttribute('value', '在这里写一些东西')", text_area)
    

导入:

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

In HTML mode, you don't see an iframe?

or

Since in Basic mode you switched to an iframe, did you switch to default content?

to solve

selenium.common.exceptions.ElementNotInteractableException: Message: element (Session info: chrome=99.0.4844.74)

You should debug your code like below:

  1. Make sure the browser is launched in full screen using

    driver.maximize_window()
    
  2. Use ActionChains:

    ActionChains(driver).move_to_element(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.ReactCodemirror>textarea")))).send_keys('something here').perform()
    
  3. Use execute_script:

    text_area = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.ReactCodemirror>textarea")))
    driver.execute_script("arguments[0].setAttribute('value', 'write something here')", text_area)
    

Imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文