无法在 confluence 上使用 selenium 和 python 定位文本输入元素

发布于 2025-01-09 16:24:22 字数 663 浏览 0 评论 0原文

我试图在汇合时单击文本区域并将一些文本发送到页面。我尝试了很多组合来查找网页上的文本输入元素,但均不成功。我使用的代码如下 -

button1 = driver.find_element_by_class_name('mce-content-body aui-theme-default mceContentBody wiki-content fullsize notranslate page-edit')
button1.click()
button1.send_keys(x) 
driver.switch_to.frame("wysiwygTextarea_ifr")

它给出了一个错误 - 没有这样的元素:无法找到元素: {“方法”:“CSS选择器”,“选择器”:“.mce-content-body aui-主题-默认 mceContentBody wiki 内容 fullsize notranslate 页面编辑”}

请帮帮我,我尝试了各种组合,但没有任何效果。 在此处输入图像描述

添加了源代码的快照。

I am trying to click inside the text area on confluence and send some text to the page. I have tried a lot of combinations to find the text input element on the webpage but have been unsuccessful. The code I am using is as below -

button1 = driver.find_element_by_class_name('mce-content-body aui-theme-default mceContentBody wiki-content fullsize notranslate page-edit')
button1.click()
button1.send_keys(x) 
driver.switch_to.frame("wysiwygTextarea_ifr")

It gives an error - no such element: Unable to locate element:
{"method":"css selector","selector":".mce-content-body
aui-theme-default mceContentBody wiki-content fullsize notranslate
page-edit"}

Please help me out have been trying various combinations but nothing worked. enter image description here

added a snapshot for the sourcecode.

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

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

发布评论

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

评论(1

九局 2025-01-16 16:24:22

通过查看您的代码和 DOM 快照,我推断您正在寻找此 DOM 组件: DOM 快照

这种情况下,你写的代码正好相反。您首先需要访问 iframe,然后您可以访问其中的元素(您的操作方式相反)

重构您的代码以与 DOM 保持一致:

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(driver.find_element_by_id("wysiwygTextarea_ifr")))
# changing the button 1 locator to xpath as the class name is too long and may not be accurate every time. data-id attribute instead would remain relatively static.
button1 = driver.find_element_by_xpath("//*[@data-id = 'wysiwygTextarea']")
button1.click()
button1.send_keys(x)

Going through your code and the DOM snapshot, I deduce that you are looking for this DOM component: DOM snapshot

In which case, the code you wrote is just opposite. You have first access the iframe and then you can access the elements inside of it (which you did the opposite way)

Refactored your code to align with the DOM:

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(driver.find_element_by_id("wysiwygTextarea_ifr")))
# changing the button 1 locator to xpath as the class name is too long and may not be accurate every time. data-id attribute instead would remain relatively static.
button1 = driver.find_element_by_xpath("//*[@data-id = 'wysiwygTextarea']")
button1.click()
button1.send_keys(x)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文