Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

Unable to use send_key() for a iframe. How to select this iframe and which element inside this should be used for send_key()?

page image

and iframe html code

<iframe class="textarea" src="/framework/html/blank.html" style="width: 99%; border-width: 1px; height: 332px;">

#document

<html webdriver="true">

<head>

</head>

<body> … </body>

</html>

</iframe>

How to send the value to the description?

One more thing i want to know that this code of frame is not coming when i go for "view page source " in browser?

1 Answer

0 votes
by (62.9k points)

driver.switch_to.frame(driver.find_element_by_tag_name("iframe")) 

assuming that the driver is a healthy instance of a web driver. To continue with the default content, write the below code:

driver.switch_to.default_content()

EDIT: When you have switched to the needed frame, locate your web element. I guess (but not sure) that in your case this will be an HTML/body, so you can do as shown below:

 el = driver.find_element_by_xpath('html/body')

It should be fine. And then you should perform the following:

el.send_keys('keys_to_send')

EDIT2: Before sending keys you may have to focus on the element (click should perform the action, and then a child element should appear). Or you can just place the below code:

 driver.execute_script('document.body = "%s"' % text_var)

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...