python selenium 无法将字符串发送到网站

python selenium cannot send string to website

我需要在在线记事本中输入一些文本,但找不到要发送的正确元素 it.You 可以找到整个页面 here

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

但出现错误:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":".//*[@id='tinymce']/p"}

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

由于'notepad'在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!")