0

i'm using selenium 2.46.0 and python 3.4 I want to put the string "Hello, world!" into the textfield for creating new letter. Am i doing this the right way? I try to switch the frame and find the right element to put the text into it. My code:

from selenium import webdriver

browser = webdriver.Firefox()
browser.get('https://mail.ru/')
browser.find_element_by_name('Login').clear()
browser.find_element_by_name('Login').send_keys('selenium90')
browser.find_element_by_name('Password').clear()
browser.find_element_by_name('Password').send_keys('pythonrocks')
browser.find_element_by_id('mailbox__auth__button').click()
browser.find_element_by_css_selector('a.b-toolbar__btn').click()
browser.find_element_by_css_selector('textarea.js-input:nth-child(5)').send_keys('07ufo@mail.ru')

browser.switch_to_frame(browser.find_element_by_id('compose_462_composeEditor_ifr'))
browser.find_element_by_class_name('mceContentBody').send_keys('Hello, world!')

selenium.common.exceptions.NoSuchElement Exception: Message: Unable to locate element: {"method":"id","selector":"compose_462_composeEditor_ifr"}

I tried:

iframe = browser.find_elements_by_tag_name('iframe')[frameindex]
browser.switch_to_frame(iframe)
browser.find_element_by_css_selector('body.tinymce').send_keys('hoo')

But it did not help

i added a screenshot of tree: enter image description here

ufo
  • 359
  • 1
  • 5
  • 11
  • possible duplicate of [Selenium and wordpress: New post test](http://stackoverflow.com/questions/23999777/selenium-and-wordpress-new-post-test) – SiKing Jun 27 '15 at 15:10

1 Answers1

2

The id of that element is dynamically generated! Try something like:

browser.switch_to_frame(browser.find_element_by_xpath('//frame[contains(@id, "composeEditor_ifr")]'))
SiKing
  • 10,003
  • 10
  • 39
  • 90