frames in selenium pytest - selenium

Hi I have parent frame called "bottomframe" inside that have two child frames called "Header" and "Main"
I would like to switch between frames "Header" and "Main" but I am not able to come out from one sub frame.
<iframe id="bottomframe" name="bottomframe" scrolling="yes" src="Home_content.aspx?C=93&L=YTERPIT%40WIN.DESY.DE&sysMsg=0" width="100%" height="100%" align="left"></td></tr></table><input type="hidden" name="iprocure24url" value="https://iprocure.eu1.inforcloudsuite.com/xfel" /></body></html></iframe>
<frameset rows="75,*" bgcolor="lightgrey" border="0"><frame src="punchoutheader.aspx?EvendorKey= 3257" name="Header" marginwidth="0" marginheight="0" width="100%" height="100%" scrolling="no"><frame src="OciPunchOutPage.aspx?EvendorKey= 3257" name="Main" marginwidth="0" marginheight="0" width="100%" height="100%"></frameset>
<frame src="punchoutheader.aspx?EvendorKey= 3257" name="Header" marginwidth="0" marginheight="0" width="100%" height="100%" scrolling="no">
</frame>
<frame src="OciPunchOutPage.aspx?EvendorKey= 3257" name="Main" marginwidth="0" marginheight="0" width="100%" height="100%">
</frame>
</frameset>
</iframe>
I tried below in pytest with selenium
driver.switch_to.frame("bottomframe")
driver.switch_to.frame("Header")
bodyText = driver.find_element_by_tag_name('body').text
print(bodyText)
This above works fine but now I would like to switch to another subframe "Main" so I tried below
driver.switch_to.frame("bottomframe")
driver.switch_to.frame("Header")
bodyText = driver.find_element_by_tag_name('body').text
print(bodyText)
# back to default web page frame
driver.switch_to.default_content()
driver.switch_to.frame("bottomframe")
driver.switch_to.frame("Main")
and i get NoSuchFrameException if I go to "Main" frame.
Could you help me out to switch between frames "Main" and "Header"

A good approach
A better way to switch frames will be to induce WebDriverWait for the availability of the intended frame with expected_conditions set to frame_to_be_available_and_switch_to_it as follows
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"Main")))
OR
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//frame[#name='Main']")))
Switching back from frame
To switch back to the Parent Frame you can use the following line of code:
driver.switch_to.parent_frame()
To switch back to the Top Level Browsing Context / Top Window you can use the following line of code:
driver.switch_to.default_content()

Related

Why does Apache Batik rasterise SVG documents transcoded to a PDF when opacity is set to less than one?

I have noticed that when I use Apache Batik to transcode SVG documents to PDF's that have an opacity set to less than one Batik will create a raster version of the SVG and place it in the pdf instead. When dealing with print this is not desirable. Is there any reason Batik does this? Is there anyway to avoid this flattening of SVG documents regardless of their opacity?
Our code to create the transcoder:
PDFTranscoder pdfTranscoder = new PDFTranscoder();
pdfTranscoder.addTranscodingHint(PDFTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, PIXEL_CONVERSION);
pdfTranscoder.addTranscodingHint(PDFTranscoder.KEY_AUTO_FONTS, false);
We then take the SVG which is returned form element.getEncodedData() as an SVG string.
TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(element.getEncodedData().getBytes()));
TranscoderOutput output = new TranscoderOutput(byteStream);
pdfTranscoder.transcode(input, output);
For opacity we edit the SVG adding a group. Consider the following svg: Note many markup tags have been removed to keep the example concise:
<svg>
<rect x="100" y="100" width="100" height="100" />
</svg>
We would edit this SVG to appear as
<svg>
<g opacity="0.5">
<rect x="100" y="100" width="100" height="100" />
</g>
</svg>

HTML2PDF on internet explorer for SVG

I'm using eKoopmans HTML2PDF on github
This is my example, my project involves using SVG and I need to display a PDF page with svg on all browsers.
Currently the SVG is not showing on Internet Explorer if you open the link on IE.
is there a way to fix this?
<div id="element-to-print">
SVG won't work on internet explorer, only google chrome
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>
</div>

Selenium switchTo frame using Frameset

<frameset border="0" rows="25,*" frameSpacing="0" frameBorder="0" onbeforeunload="doUnload()" onunload="doUnload()" onkeydown="fn_KeyDown(event)">
<frame name="link" scrolling="no" src="Links.aspx?FromWhere=DB" marginwidth="0" marginheight="0" BORDER="0" target="_self">
<script >
alert('');</script>
<frame id="Sub" src="../Home/Home.aspx?FromWhere=DB" scrolling="Yes" name="Sub" >
</frameset>
How to switchto the frame here and perform operations in selenium?
If you want to switch to first frame driver.switchTo().frame(driver.findElement(By.cssSelector("frame[name='link']")));
If you want to switch to the Second frame with name 'Sub'
driver.switchTo().frame(driver.findElement(By.cssSelector("frame[name='Sub']")));
or
driver.switchTo().frame(driver.findElement(By.cssSelector("frame#Sub")));

Htmlunit access to a frame inside a frameset which is inside a frameset

I need to access to a form element which is in the frame "menu"
<html>
<head>
<script>.........
</script>
<title>The Main page</title>
</head>
<frameset onload="init();" rows="70,*" frameborder="0" border="false" framespacing="0">
<frameset cols="32000,0,0" frameborder="0" border="true" framespacing="0">
<frame scrolling="no" marginheight="0" marginwidth="0" target="logo" src="about:blank" name="logo"></frame>
<frame scrolling="no" noresize="" marginheight="0" marginwidth="0" target="temp" src="about:blank" name="temp"></frame><frame scrolling="no" noresize="" marginheight="0" marginwidth="0" target="system" src="about:blank" name="system"></frame>
</frameset>
<frameset cols="165,*" frameborder="0" border="false" framespacing="0">
<frame scrolling="no" noresize="" marginheight="0" marginwidth="3" target="menu" src="about:blank" name="menu"> </frame>
<frame scrolling="auto" noresize="" marginheight="0" marginwidth="3" target="work" src="about:blank" name="work"></frame>
</frameset>
</frameset>
</html>
I tried this:
menuPage = (HtmlPage)page.getFrameByName("menu").getEnclosedPage();
But what I get is
<?xml version="1.0" encoding="ISO-8859-1"?>
<html>
<head/>
<body/>
</html>
I tried different other odd thing but never succeed to get the content of the frame.....
If somebody have already done this I will be happy to get some clues..
Ok, I found it eventually. The javascript was loading. But besides and most important I was not accessing correctly the frame content. So By looking deeply in the dom with firstchild and sibbling I arrived to see what I was looking for. So the first code working is the following and need some tweaks:
HtmlElement frameset1 = page.getBody();
node = frameset1.getFirstChild().getNextSibling();
HtmlFrame fr1 = (HtmlFrame) node.getFirstChild();
FrameWindow fw1 = (FrameWindow) fr1.getEnclosedWindow();
HtmlPage p1 = (HtmlPage) fw1.getEnclosedPage();
Thanks for your time

show pdf file in a icefaces modalpopup

Is it possible to show a pdf file in modalpopup with icefaces. Tried this but does not seem to work. Am new to icefaces too.
<ice:panelPopup autoCentre="true" visible="#{popup.visible}" modal="true">
<f:facet name="header"/>
<f:facet name="body">
<OBJECT DATA="/ICEfacesDevelopersGuide.pdf" TYPE="application/pdf" WIDTH="100%" HEIGHT="100%" />
<ice:commandButton value="Close" action="#{popup.close}" />
</f:facet>
</ice:panelPopup>
I ended up doing it the old way opening it on a new window or tab using output link and target attribute.