Embed Element: Could not access DOMWindow Context - java

I have a page with a JS Function called test (e.g.), and, in one page of my app I have to open a Java Applet.
In google chrome, it opens as an embed element, and in firefox in an object.
Sometimes, in my applet, I have to call my JS function to do something in the page. I doing this with:
applet.getAppletContext().showDocument(new URL("javascript:window.test();"));
In browser that use the object, this code work like a boss, but, if it use embed, it do nothing, trowing a exeption in Browser console, saying that the Window does not have a "test" function.
I think thi is some trouble with embed context and document context, but I dont know how to fix it, or, if it is "fixable".
So, I like to know if is there any workaround to make it work.
thanks in advance.

I found the problem.
A minor update of chrome solve it. I dont know if the problem was in Webkit or in chrome itself, but, now it works.

Related

Java Phantomjs behaving different in windows and linux

I been trying to solve this issue but not sure what's the cause for this,
i made a program with java and phantomjs, and in theory they both should behave the same way.
Phantomjs in both the pc and the server is the same v.2.0.
In windows(v.7) mi testing program works as expected, but in linux (debian) the program fails, with this error when it tries to click an element:
Caused by: org.openqa.selenium.NoSuchElementException: {"errorMessage":"Unable to find element with css selector
Now, i know sometimes we have to wait for few seconds for the page to load, which already do (even added a few more just to be sure) and it was tested correctly in windows.
i tried with the click function:
element.click();
with a javascript code:
JavascriptExecutor js = (JavascriptExecutor)driver;
js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element)
and with actions too:
Actions action = new Actions(driver);
action.moveToElement(element).contextClick().build().perform();
//and this code too
action.moveToElement(element).click().build().perform();
Anyone had this same or similar issue? what i else i can do? i'm stuck since yesterday and i wan't able to figure out this problem.
note: for now i have an alternate way to get page without having interaction, but still having different results from the web page when executing in different OS, for example:
where i normally i get this link: www.somesite.com/?search=xxxxx&date_in=dd/MM/yyyy&params=etc. , instead i get www.somesite.com/?search=xxxxx, the default search without any especific search parameters.
You need to use onResourceError callback, to find out what's going wrong.
You also need to use the following Command-Line options:
--ignore-ssl-errors=true --ssl-protocol=any --debug=true
See also: this issue.

Best way to call a JavaScript function from an Java Applet

I export a method to javascript window with JSNI, and I want to call this function from a applet in a GWT application..
I think that sometimes I have problems with Window context, so, I do some research and found the JSObject class.
I afraid with the package name (netscape.javascript). Is this class still be used? Is there another better way to do this?
I already tried to get applet context and show a new URl (with javascript:myFunction();), but, in some browsers it redirects the user to a new blank window...
What can I do to make it works best as possible?
Thanks in advance.
The netscape.javascript package is included with every Oracle JRE that I am aware of. Not entirely sure about the others.

How to render a web page with android jdk?

I want to show the web page normally,but still keep the user in my app,
how to make use of the available web render engines programmatically?
UPDATE
I'm now using the webview ,but can't render the page,reporting 404 page not found.
However,when I pack my project and run in another computer,it works like charm!
How to solve this?
Use a webview and implement webkitclient if needed.
More info here
Please explain your question. I cant understand that you want to open the webview with the URL or by the html code. Both of them is totally different. Please explain how do you want to open the webview in application by URL or by HTML
You, as of now, probably let your app open the device web browser to let the user see the content of the URL, via an Intent Action.
Use your activity which uses a WebView and implements its own WebKitClient. Then you can make the user stay in your app and control what and how content is fetched.
#Achie has a nice link for you which explains how Web things work in Android.
To know how to work with WebViews, go to this URL and read the nice article-cum-tutorial

Java Applet: how to simulate an url has been clicked?

Basically I want my Java Applet to simulate an url has been clicked, once a certain event listener has been executed.
Say, before I have a link in html:
<a href='destinationpage.php?pid=1001' target='rightFrame' />
I'd like to keep the same link to php intact, and when Applet actually invoke the click simulation method, the "target" attribute can also be used to control the behavior.
Similar SO thread found at here, but it doesn't have an answer.
I have little experience in this area, but I am okay with Java programming so long as someone can give me the suggestion of where to get started with.
Many thanks in advance.
Edit:
Okay, tried to get JSObject from the netscape.javascript package to work, added plugin.jar into CLASSPATH, unfortunately I finally got an ExceptionInInitializerError, so this approach failed, unless I can know how to debug in such a mess...
You could call the url directly in the applet but if you want to reference the link in the page something like the following should work. I have not tested this though.
getAppletContext().showDocument(new URL("javascript:function() {
document.getElementById('mylink').click();
}"));
}

Testing onbeforeunload events from Selenium

I'm trying to write a Selenium test for a web page that uses an onbeforeunload event to prompt the user before leaving. Selenium doesn't seem to recognize the confirmation dialog that comes up, or to provide a way to hit OK or Cancel. Is there any way to do this? I'm using the Java Selenium driver, if that's relevant.
You could write a user extension (or just some JavaScript in a storeEval etc) that tests that window.onbeforeunload is set, and then replaces it with null before continuing on from the page. Ugly, but ought to get you off the page.
I've just had to do this for an application of mine where the onbeforeunload handler brings up a prompt if a user leaves a page while a document is in an unsaved state. Python code:
driver.switch_to.alert.accept()
The Java equivalent would be:
driver.switchTo().alert().accept();
If the alert does not exist, the code above will fail with a NoAlertPresentException so there is no need for a separate test to check the existence before accepting the prompt.
I'm running Selenium 2.43.0 but I think this has been doable for a while now.
In cases where I don't want the prompt to come up at all because that's not what I'm testing, I run custom JavaScript in the browser to set window.onbeforeunload to null before leaving the page. I put this in the test teardown code.
faced same problem with "beforeunlaod" event listner, LUMINUS! a chrome addon that helps me just block the event listener in the plugin thats all..
When I was confronted with limited control which I had over browser using Selenium, I turned to MozLab plugin which solved my problem if only for one browser platform.

Categories

Resources