html中的Selenium和iframe [英] Selenium and iframe in html
问题描述
无法对iframe使用send_key()。如何选择这个iframe以及其中的哪个元素应该用于send_key()?
Unable to use send_key() for a iframe. How to select this iframe and which element inside this should be use for send_key()?
和iframe html代码
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>
如何将价值发送到描述?
我还想知道,当我在浏览器中查看查看页面源代码时,这段代码不会出现吗?
One more thing i want to know that this code of frame is not coming when i go for "view page source " in browser?
推荐答案
driver.switch_to.frame(driver.find_element_by_tag_name(iframe))
假设该驱动程序是一个健康的webdriver实例。要继续使用默认内容,请执行 driver.switch_to.default_content()
driver.switch_to.frame(driver.find_element_by_tag_name("iframe"))
assuming that driver is a healthy instance of webdriver. To continue with the default content do driver.switch_to.default_content()
编辑 :当你切换到所需的框架时,像往常一样找到你的元素。我想(但不确定)在你的情况下这将是一个html / body,所以
EDIT: When you have switched to needed frame, locate your webelement as you always do. I guess (but not sure) in your case this will be a html/body, so
el = driver.find_element_by_xpath('html / body ')
应该没问题。并执行
el.send_keys('keys_to_send')
EDIT2 :在发送密钥之前,您可能必须关注元素(单击应该执行操作,应显示子元素)。或者您可以通过JS放置所需的文本。
EDIT2: Before sending keys you may have to focus on the element (click should do the thing, a child element should appear). Or you can just place the needed text via JS.
driver.execute_script('document.body.innerHTML =%s'%text_var )
这篇关于html中的Selenium和iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!