0

I am trying to enter a comment in the following text box with details as

<input type="text" name="com_data" value="" size="40">

I tried the following:

driver.find_element_by_class_name("Comment:").send_keys("hello")
# driver.find_element_by_name('btnSubmit').click()
# driver.find_element_by_name("com_data").send_keys("hello smirajka")
driver.find_element_by_xpath("//input[@name='com_data']").send_keys("hello")

All of the above attempts failed with error message as:

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@name='com_data']"}
  (Session info: chrome=55.0.2883.95)
  (Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.11.6 x86_64)
Andersson
  • 51,635
  • 17
  • 77
  • 129
Simmi
  • 1
  • 5
  • Is this element is in a frame ? – iFlo Jan 13 '17 at 10:17
  • Yes, it is inside a frame. – Simmi Jan 13 '17 at 10:18
  • So your issue is that you need to get in the frame before finding the element. Please see this http://stackoverflow.com/questions/20069737/how-to-identify-and-switch-to-the-frame-in-selenium-webdriver-when-frame-does-no – iFlo Jan 13 '17 at 10:19

1 Answers1

0

To handle element inside an iframe, try to switch to this iframe before sending text:

driver.switch_to_frame('iframe_id_or_name')
driver.find_element_by_xpath("//input[@name='com_data']").send_keys("hello")

If there is no id / name set to iframe:

driver.switch_to_frame(driver_find_element_by_tag_name('iframe'))

If there are multiple iframe elements on page, you can access them by index:

driver.switch_to_frame(driver_find_elements_by_tag_name('iframe')[0])

To switch back you might need to use:

driver.switch_to_default_content()
Andersson
  • 51,635
  • 17
  • 77
  • 129