A block of code, from the webpage I'm working on looks like the following -
<div class="A">
<iframe id="frameA">
#document
<html style>
<head></head>
<body style>
<p style>Random Text Goes Here</p>
</body>
</html>
</iframe>
</div>
I would like to extract the text in the paragraph tag, "Random Text Goes Here". However, many articles on the internet suggest that iframes cannot be identified directly using an XPath or a CSS Selector like divs and spans are, using their classes or ids. I've experienced the same, upon trying this piece of code -
exem = driver.find_element_by_tag_name("frameA")
driver.switch_to.frame(exem)
required_field = driver.find_element_by_xpath("html/body/p").text
print(required_field)
I'm not sure if the aforementioned code is even right, but I've just tried doing this on the basis of things I've understood from some online sources. This fails to find the paragraph in the iframe, i.e. a NoSuchElementException
is raised.
Can someone help me out with this?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…