【问题标题】:How can I send text to text editor with Python Selenium?如何使用 Python Selenium 将文本发送到文本编辑器?
【发布时间】:2022-01-11 06:00:30
【问题描述】:

我想用 Selenium 向帖子编辑器发送文本,但是我遇到了 xpaths 的问题,我该如何解决?

错误代码:

弃用警告:不推荐使用 find_element_by_* 命令。请 使用 find_element() 代替元素 = driver.find_element_by_xpath("/html/body").send_keys(DETAIL)

我的代码

element = driver.find_element_by_xpath("/html/body").send_keys(DETAIL)

我要发送文本的部分

【问题讨论】:

    标签: python forms selenium xpath


    【解决方案1】:
    driver.find_element_by_xpath("/html/body").send_keys(DETAIL)
    

    应该是由于折旧还进口的。

    driver.find_element(By.CSS_SELECTOR,".cke_editable.cke_editable_themed.cke_contents_ltr").send_keys(DETAIL)
    

    你还有一个 iframe,所以先切换到那个。

    WebDriverWait(driver,30).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,".cke_wysiwyg_frame.cke_reset")))
    

    进口:

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

    【讨论】:

    • 但我是用python写的
    • 这是python。
    • 问题依旧
    • 你能发布 iframe 的 html 元素吗?我需要它的 css 选择器以及发送键所在的 whaetever 输入元素。
    • #cke_1_contents > iframe
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 2021-06-12
    • 1970-01-01
    相关资源
    最近更新 更多