【问题标题】:python selenium cannot send string to websitepython selenium 无法将字符串发送到网站
【发布时间】:2015-10-22 18:38:59
【问题描述】:

我需要在在线记事本中输入一些文字,但找不到合适的元素来发送。您可以找到整页here

我试试:fox.find_element_by_xpath(".//*[@id='tinymce']/p")

但发生错误:

selenium.common.exceptions.NoSuchElementException:消息:无法 定位元素:{"method":"xpath","selector":".//*[@id='tinymce']/p"}

我也尝试: fox.find_element_by_xpath("//div[contains(.,'Working')]") 没有错误但没有输入字符串

【问题讨论】:

    标签: python selenium find element


    【解决方案1】:

    由于“记事本”在iframe 中,您首先需要切换到特定框架。试试这个:

    fox.switch_to.frame(fox.find_element_by_id("page_text_ifr"))
    notepad = fox.find_element_by_id("tinymce")
    notepad.send_keys("Hello World!")
    

    或者因为你使用 XPath:

    fox.switch_to.frame(fox.get_element_by_xpath("//iframe[@id='page_text_ifr']")
    notepad = fox.get_element_by_xpath("//body[@id='tinymce']")
    notepad.send_keys("Hello World!")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-19
      • 2018-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多