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

Unable to locate text input element using selenium and python on confluence

我试图在 confluence 的文本区域内单击并向页面发送一些文本。我尝试了很多组合来找到网页上的文本输入元素,但都没有成功。我使用的代码如下 -

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"}

请帮助我尝试各种组合,但没有任何效果。

为源代码添加了快照。

通过你的代码和 DOM 快照,我推断你正在寻找这个 DOM 组件:DOM snapshot

这样的话,你写的代码正好相反。您首先访问 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)