javascript Error: Permission denied to access property 'u8' - javascript

i have a legacy jsp page which has button element . i am using frameset/frames. on click of this button function parent.u8() is called.
But as soon as i click on button,i get below error
Error: Permission denied to access property 'u8'
parent.u8()
Its a big jsp. so i dont want to paste complete content here. I tried to take the bare minimum html markup from server generated html page
and created the html page with similar structure it works fine there.But not in real application.
Just for information there is one iframe elemet also but that is lying altogether in separate frame not in the frame where button exists(so possiblity something related to iframe looks bleak to me).
u8 function lies inside top head Tag. Folks i know its tough to tell what can be exact reason without actual markup but probably you can help
me regarding the possible reasons when can i get this kind of excpetion Permission denied to access property
Update:-
This was working before. Issue began when i started using tinymce(WYSIWYG) editor in one of the frame.Tinymce created one iframe element but that is loaded from appserver only. Pasting below the code generated inside body of one of the frame. May be it helps
<span id="bodyTest_parent" class="mceEditor defaultSkin" role="application" aria-labelledby="bodyTest_voice">
<span id="bodyTest_voice" class="mceVoiceLabel" style="display:none;">Rich Text Area</span>
<table id="bodyTest_tbl" class="mceLayout" cellspacing="0" cellpadding="0" role="presentation" style="width: 100%; height: 323px;">
<tbody>
<tr class="mceFirst mceLast">
<td class="mceIframeContainer mceFirst mceLast">
<iframe id="bodyTest_ifr" frameborder="0" src="javascript:""" allowtransparency="true" title="Rich Text AreaPress ALT-F10 for toolbar. Press ALT-0 for help" style="width: 100%; height: 323px; display: block;">
<!DOCTYPE >
<html>
<head xmlns="http://www.w3.org/1999/xhtml">
<body id="tinymce" class="mceContentBody " onload="window.parent.tinyMCE.get('bodyTest').onLoad.dispatch();" spellcheck="false" dir="ltr">
<p>
<span color="blue" data-mce-style="color: blue;" style="color: blue;">
<strong>adain</strong>
</span>

This is usually caused by the frames existing on different origins (e.g. domains). JavaScript is not allowed to access data from different origins for security reasons.

Related

Unable to make collapsible work on webpage

I'm attempting to made a collapsible (and hopefully simple) DIV and was working with another answer I had found here on stack overflow but I cannot seem to get it to work on my website. I do have a fiddle with the full links and coding which shows that its actually working (in the fiddle) but then I input the code into my page and it hides the stuff beneath the first picture (using that as the divider) but when I click on it nothing happens (it doesn't display)
Below is the snippet of HTML coding:
<p class="expand-one"> <img src="https://www.mywebsite.net/something/vip1.png"></p>
<p class="content-one">
<td width="33%" align="center" valign="top">
<br>
</td>
<td width="33%" align="center" valign="top">
<a href="http://www.mywebsite.net/bigslice" title="The Big Slice: Home of the Edge">
<font color="#dace77">[ m u s i c ]</font>
</a><br>
<font color="#FAF9B6">$ROOMNAME bigslice$</font><br>$USERLIST bigslice$<br>
</td>
</tr>
</p>
and up in my CSS I have the simple addition of:
<style>p.content-one {
display: none;
}
</style>
And down before the body ends where all my JS scripts are I have
<script>
$('.expand-one').click(function() {
$('.content-one').slideToggle('slow');
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
Since the answer was as simple as jQuery not loading before the code using it, I thought I'd post the troubleshooting steps I suggested as an answer. The question may be marked as a duplicate, but if not, maybe someone will stumble upon it and be helped... idk.
Ensure any code using jQuery is added after the jQuery library is included (typically I include jQuery at the end of the body and any custom script after that, but that's personal preference).
Check the brower console (F12) for errors- typically these are easy to grok, or you can search for the error message.
If jQuery attempts to select an element before the element is added (either because the jQuery comes before the HTML code, or because the HTML code is dynamically added after loading), it won't find an element- thus adding a listener won't do anything. Either ensure the code comes after the element, attach the listener to a parent/ancestor and specify which element to listen for (e.g. $(document).on('click', 'p', function() { /*...*/ }) will attach a listener to the entire document which will only run when a paragraph is clicked), or use $(function() { /* code here */ }) to ensure your code doesn't run until the page is done loading.
console.log() is extremely helpful if you're not sure if code just won't run, or if it's running and just not affecting anything. If nothing logs, the code isn't running.

Can't click on the anchor inside a frame with href value as javascript using selenium

Can't click on the anchor inside a frame with href value as javascript using selenium.
#Note: I could manually click/ call the javascript from IE developer console all looks good. The issue is only through selenium .
Here is the page source like
<html>
<body>
<p>
<iframe name="iframe1" width="100" height="218" src="about:blank" frameborder="0" marginwidth="0" "marginheight="0" scrolling="yes">
<html>
<body>
<div class="className" id="DivName"onmouseover="startLinkHover(0,70)" onmouseout="stopLinkHover()">
<a name="link0" href="javascript:function()" shape=""> This is link 1 </a>
</div>
</body>
</html>
</iframe>
</p>
</body>
</html>
I am working with c# ,IE and selenium
Selenium.WebDriver.IEDriver" version="2.53.1.1"
Selenium.WebDriver" version="3.0.0"
Selenium.Support" version="3.0.0"
IE 11 ( As my web application only support IE)
Here is what i have tried:
As it the page is consisting of iframe
1) I am switching to iframe and find the anchor using the name and click
driver.SwitchTo().Frame(driver.FindElement(By.Name("iframe1"));
driver.FindElement(By.XPath("//a[#name='link0']")).click();
2) I have also tried to extract the href property into a string variable and tried to execute the javascript using Javascript executor.
driver.SwitchTo().Frame(driver.FindElement(By.Name("iframe1"));
var js=driver.FindElement(By.XPath("//a[#name='link0']")).GetAttribute("href");
var jsDriver = (IJavaScriptExecutor)driver;
jsDriver.ExecuteScript(js);
Please excuse if any typos as i don't want to post the html source here i have explained my issue with a sample.
Thank you
Finally i managed to resolve this issue by reloading the project from source control after pointing the .net framework target version to 4.5 instead of 4.52 (not sure why would this be?).
after investigations , it was proved that issue was not with selenium clicking on the element but the execution of java script after that with page loads.

Not able to type in Rich Text Editor

I want Selenium to type a text in a Rich Text iframe, but I can't get it to work. This is the iframe: <iframe src="" frameborder="0" class="cke_wysiwyg_frame cke_reset" style="width: 1635px; height: 100%;" title="Rich Text Editor, question" aria-describedby="cke_94" tabindex="0" allowtransparency="true"></iframe>
My steps are:
$this->selectFrame("xpath=//*[contains (#class, 'cke_wysiwyg_frame')]");
$this->type("xpath=//*[contains (#class, 'cke_wysiwyg_frame')]", $this->contextQuestion);
It says that, for some reason, it doesn't find the element, maybe it doesn't load the JS ?. Any help would be appreciated!
Not sure, but you may have to tell Selenium to execute Javascript code. Once you have the class name, you might be able to use ? jQuery ? and populate the CKEditor that way. I had solved this a few months ago, and no longer have access to my code (it was code-for-hire).
Perhaps these 3 links could provide some help.
How to use SendKeys(webdriver) command in Rich Text editor that is located in iframe
http://yizeng.me/2014/01/31/test-wysiwyg-editors-using-selenium-webdriver/
https://code.google.com/p/selenium/issues/detail?id=7087

How to access a <div> from the HTML embedded by <object>

I have a webpage that has several <div> sections ("navcol" and "maincol"). The "navcol" div contains <object data="mypage.html">. Inside mypage.html there are buttons the user can click to select pages to be inserted into "maincol". I need to gain access to the innerHTML of "maincol" in the main page with Javascript, so I can do the insertion (like using an iframe). Can someone put me on the right track?
PS. I am using <object>, because I want to have HTML 4.0 "Strict" and Iframes are not in "Strict", but s are.
From within the page in the object element, you can get access to the upper–most browsing context using:
window.top.document
so you can try:
window.top.document.getElementById('maincol');
no doubt only within limitations imposed by the same–origin policy though.
e.g.
<div id="mailcol">maincol</div>
<div id="navcol">
<object data="foo.html"></object>
</div>
in foo.html:
<button onclick="
alert(window.top.document.getElementById('mailcol').innerHTML)
">button</button>

Grab control value from separate file in ASP website?

I have two separate .aspx files that are used in one web page. One for the header and the other for the body. In the javascript for the body file, how would I grab the value of an asp:label control from the header? It's name is "lblName", so I tried simply document.getElementById("lblName").value and I received the error:
Microsoft JScript runtime error: Object required
This site is written in Visual Basic, so I'm wondering if anyone knows how to do this from the code behind as well.
If I hit F12 in the browser (IE) this is the hierarchy I see:
<head>
<frameset rows="147,*" frameBorder="no" frameSpacing="0">
<frame name="frHeader" id="frHeader" src="DistHeader.aspx?statProducer=0707090003" noResize="noresize" scrolling="auto">
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
<html>
<head>
<body topMargin="1" rightMargin="0" bottomMargin="0">
<div class="clsNoPrint">
<div class="clsNoPrint">
<table width="100%">
<tbody>
<tr class="clsNameBar" width="100%">
<td width="*" align="left">
<span class="clsNameBar" id="lblName" style="width: 100%;">
If you have runat="server" on your label than its id in browser will be different from one you see on server.
You must pass its ClinetID to JS somehow. For instance, with Page.RegisterStartupScript or if your JS is a part of aspx file you can do something like this:
document.getElementById('<%=lblName.ClientID %>')
Another problem: I guess lblName is <asp:Lable /> which is converted to span which has no .value, but you can use something like this:
document.getElementById('<%=lblName.ClientID %>').innerHTML
As you are using frames - depending on where your code is located you need to access frame first:
//Chrome, FF
document.getElementById("frHeader").contentDocument.getElementById("lblName")
//IE (it does not support contentDocument and have document instead)
document.getElementById("frHeader").document.getElementById("lblName")
Suppose your code is in outer document, which contains actually contains a frame. But if it is in another frame - you should add window.parent. before document.getElementById
Since this was a website that was created almost ten years ago, we had to go up the ladder in the frameset to get the value we were looking for. The code below was the method used
var el = parent.parent.frames("frHeader").document.getElementById("lblName").innerText;

Categories