HTML code:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-15" />
<script type="text/javascript">
var foo;
function test(s)
{
foo = s;
alert(foo);
}
window.onload = function ()
{
foo = 'init';
document.getElementById('foo').doit();
alert(foo);
}
</script>
<body>
<applet id="foo" code="TestApplet.class"
archive="TestApplet.jar" width="0" height="0"></applet>
</body></html>
Java applet code:
public void doit ()
{
try {
getAppletContext().showDocument(
new URL("javascript:test(\"foobar\")"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
When I call this HTML page :
In IE (8) I get: First popup ("foobar"), second popup ("foobar").
In Firefox (19.2, 30.0) I get: First popup ("foobar"), second popup ("init").
Can anybody explain why? Obviously, foo is written by the applet only temporarily.
Many thanks in advance.
Related
I am trying to automate a page which has various element types. I am able to login and navigate till that page using Protractor,TypeScript,jasmine2 combination
When i try to enter a text in a field, it throws
Message: Failed: element not interactable.
Does it mean that the entire ng-controller or ng-scope is disabled for element interaction for automation?
Please let me know a solution if there is a way to enable the elements in the page on pageLoad ?
import { browser, by, element } from 'protractor';
import { Locator } from 'protractor/built/locators';
import { PageObjects } from '../TestPageObjects/OR';
import { TestData } from '../TestData/TD';
var po= new PageObjects();
var data= new TestData();
describe('Login', function() {
it('Login to Server', function() {
browser.get('http://server01/test/testapp.html');
element(<Locator>by.xpath(po.login_username)).sendKeys(data.username);
element(<Locator>by.xpath(po.login_password)).sendKeys(data.password);
element(<Locator>by.xpath(po.login_loginBtn)).click();
element(<Locator>by.xpath(po.MainMenu_setup)).click();
element(<Locator>by.xpath(po.SETUP_company)).click();
element(<Locator>by.xpath(po.COMPANY_companyDetails)).click();
browser.switchTo().frame(element(by.id('ifmPortalInfrastturcture')).getWebElement());
browser.sleep(10000);
browser.element(<Locator>by.xpath(po.CompanyName)).clear();
browser.element(<Locator>by.xpath(po.CompanyName)).sendKeys('ANN');
});
});
I expected the behavior to be like entering the text but the terminal showed element not interact-able.
PageObject (PO) selector is below:
export class PageObjects
{
public login_username: string ='//*[#id="username"]';
public login_password: string ='//*[#id="password"]';
public login_loginBtn: string ='//*[#id="btnSubmit"]';
public MainMenu_setup: string ='//a[span[text()="Setup"]]';
public SETUP_company: string ='//a[span[text()="Company"]]';
public COMPANY_companyDetails: string ='//a[span[text()="Company Details"]]'
public CompanyName: string = '//label[contains(.,"Company Name")]/following::input[1]';
//a[span[text()="Receipts"]]
//a[span[text()="Control Text"]]
}
HTML Page is below:
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="portalInfrastructure" dir="ltr">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>iProof Axon</title>
<link rel="icon" href="favicon.ico" type="image/ico" />
<style>
#font-face {
font-family: 'FontAwesome';
src: url('iProofCDN/Templates/Default/Styles/LTR/assets/css/Common/icons/fontawesome/fonts/fontawesome-webfont.eot?v=4.7.0');
src: url('iProofCDN/Templates/Default/Styles/LTR/assets/css/Common/icons/fontawesome/fonts/fontawesome-webfont.eot?#iefix&v=4.7.0') format('embedded-opentype'),
url('iProofCDN/Templates/Default/Styles/LTR/assets/css/Common/icons/fontawesome/fonts/fontawesome-webfont.woff2?v=4.7.0') format('woff2'),
url('iProofCDN/Templates/Default/Styles/LTR/assets/css/Common/icons/fontawesome/fonts/fontawesome-webfont.woff?v=4.7.0') format('woff'),
url('iProofCDN/Templates/Default/Styles/LTR/assets/css/Common/icons/fontawesome/fonts/fontawesome-webfont.ttf?v=4.7.0') format('truetype'),
url('iProofCDN/Templates/Default/Styles/LTR/assets/css/Common/icons/fontawesome/fonts/fontawesome-webfont.svg?v=4.7.0#fontawesomeregular') format('svg');
font-weight: normal;
font-style: normal
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
</head>
<body ng-controller="PortalInfrastructureController as menuList" class="pace-done " ng-init='setPageUrlByPageType("Authenticate", "#pageManager")' id="bdyPageManager">
<div id="pageManager"></div>
<div id="MultiWindowRight" class="noItem " style="display:none">
<img data-imgsrc="/Templates/Default/Styles/LTR/assets/images/RightArrow.png" />
<div class="MultiWindow"></div>
</div>
<script type="text/javascript" src="iProofCDN/Templates/Default/Scripts/JsBundle/Common/ProofConfig.js"></script>
</body>
</html>
<script type="text/javascript">
window.top.ScriptLoader('PageManager', window.document, function () {
//default
});
</script>
with some research one of my colleague found a solution.
The container elements were hidden for access and we unlocked using the following script:
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.getElementById('Parks').style.display='block';");
NOTE: a Div named "Parks" was a child inside the xmlns which is again a child of an iFrame.
Does Eclipse Orion WebIDE support JSP? I am trying to create a simple application and jsp files are not working.
index.html
<html>
<head>
<script type="text/javascript" src="jquery-1.12.4.js"></script>
<script>
function getInput()
{
$.ajax({
type:"GET",
url: "./test.jsp",
success: function(success) {
console.log(success);
}
});
}
</script>
</head>
<body onload="getInput()">
test.jsp
<%#import="./javaMethod*"%>
<%javaMethod a = new javaMethod();
var value = a.initiate();
%>
<input type="hidden" id="test" value="<%=value%>">
javaMethod.java
public class javaMethod
{
public int initiate()
{
return 1;
}
}
This should add a hidden input field which will hold the value from the java method. However, it is not working and the jsp is just displaying as plain text.
This should add a hidden input field - no, this should log anything comes from test.jsp to the browser console. To add the output of the JSP to the body element, use $(document.body).append(success);.
i am new on Play Framework and i am trying to develop sample java application
i have created new html page test.html
in controllers it is working if we simply return result in the form of string i.e. return ok("hello world") but it simply format all the styling/text and just shows "hello world" on the UI.
public static Result test() {
return ok("hello world");
}
// working fine
but it gives errors when i try this
public static Result test(){
return ok(test.render());
}
// giving error
it gives following errors
[error] /opt/ahsen/play-2.2.3/testapp/app/controllers/Application.java:15: render(java.lang.String,play.api.templates.Html) in views.html.test cannot be applied to ()
[error] return ok(test.render());
[error] (compile:compile) javac returned nonzero exit code
here is my test.html file
#(title: String)(content: Html)
<!DOCTYPE html>
<html>
<head>
<title>#title</title>
<link rel="stylesheet" media="screen" href="#routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="#routes.Assets.at("images/favicon.png")">
<script src="#routes.Assets.at("javascripts/jquery-1.9.0.min.js")" type="text/javascript">
</script>
</head>
<body>
#content
</body>
</html>
help please
Your test.html template requires two parameters
#(title: String)(content: Html)
So you need to pass them to the template in your controller
public static Result test(){
String title = "test title";
Html content = // create content
return ok(test.render(title, content));
}
Better solution
Test.html looks rather as a more general layout template. I would create a separate file for generating content instead passing it directly from a controller.
content.html
#(title: String)
#test(title){
<span>this is the content</span>
}
And in the controller it would look like this.
public static Result test(){
String title = "test title";
return ok(content.render(title));
}
I thought I would try my hand at applets - I made an applet using Eclipse. It runs fine using the Run As -> Java Applet.
I read a bit about running it outside Eclipse, so I did the following:
Made a folder.
Created New -> Java Project [applet_test].
Inside the project, I created New -> Other -> Visual Swing Class -> Applet [Number1] - that created Number1.class.
Added code and ran it as a Java applet - it ran fine.
Exported the project as a JAR file (not a runnable JAR file).
Wrote HTML using TextEdit (Mac's version of Windows' Notepad). The HTML follows, below...
I put the JAR file, HTML and .class file in the folder.
In Terminal (Mac's version of Windows command prompt window), I ran Appletviewer applet_testX2.html (that's the name of my HTML).
I could see a brief flash of the application name at the top of the screen (as would any other running application).
However, the application (which should display a Jpanel with a label and a button) did NOT appear. I also tried running it from Firefox and Safari. Only the HTML code appeared.
So, what am I doing wrong? And, more importantly, how do I do it correctly?
Code follows without imports statements:
<html>
<body>
<applet code="Number1.class" archive="applet_test.jar"
width=300
height=300>
</applet>
</body>
</html>
The Java code:
public class Number1 extends JApplet {
public Number1() {
}
private static final long serialVersionUID = 1L;
#Override
public void init() {
try {
EventQueue.invokeAndWait(new Runnable() {
#Override
public void run() {
initComponents();
}
});
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private void initComponents() {
setSize(320, 240);
JPanel panel = new JPanel();
getContentPane().add(panel, BorderLayout.CENTER);
JLabel lblAppletTest = new JLabel("Applet test 1");
panel.add(lblAppletTest);
JButton btnPushIt = new JButton("Push it");
panel.add(btnPushIt);
}
}
Firefox source view:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Author" content="BT">
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1038.35">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Helvetica; min-height: 19.0px}
</style>
</head>
<body>
<p class="p1"><html></p>
<p class="p1"><span class="Apple-converted-space"> </span><body></p>
<p class="p1"><span class="Apple-converted-space"> </span><applet code="Number1.class" archive="applet_test.jar"</p>
<p class="p2"><br></p>
<p class="p1"><span class="Apple-converted-space"> </span>width=300</p>
<p class="p1"><span class="Apple-converted-space"> </span>height=300></p>
<p class="p1"></applet></p>
<p class="p1"></body></p>
<p class="p1"></html></p>
</body>
</html>
My guess is that here:
<applet code="Number1.class" archive="applet_test.jar"
you're not taking packages into consideration. For instance, if the package is myPackage.vol3 then the line should read
<applet code="myPackage.vol3.Number1.class" archive="applet_test.jar"
But if this doesn't help, you'll want to extract any error messages that the browser gives you and edit your original post to show us what they are.
Using Appletviewer
------------------
Write code of Applet.
If you installed tomcat in D:
code
-
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class MyApplet extends Applet
{
public void init()
{
System.out.println("init intilize");
GridLayout g=new GridLayout(4,6,0,0);
setLayout(g);
MyListener m=new MyListener();
for(int i=1;i<=12;i++)
{
Button b=new Button("ok"+i);
add(b);
b.addActionListener(m);
}
}//end of init
public void start()
{
System.out.println("applet started");
}//end of start
public void stop()
{
System.out.println("applet stop");
}//end of
public void paint(Graphics g)
{
g.drawString("Naveed",200,25);
g.drawOval(20,30,30,20);
System.out.println("applet paint");
}//end of start
public void destroy()
{
System.out.println("applet destroy");
}//end of start
}
class MyListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.out.println("button clicked");
}//end of actionPerformed
}
Now save this code in D:, not in sub folder.
First Compile it.
open the cmd
cd D:
type
`javac MyApplet.java -d classpath D:\Tomcat\common\lib\servlet.jar`
This will make a MyApplet.class file
Now make a html file.
<html>
<body>
<applet code="Number1.class" width=30 height=300 > </applet>
</body>
</html>
Save with the name of you want let's say app.html
run the html file now.
In the cmd window
appletviewer app.html
Output will be in front of you.
I have a web page with an applet as the only element that looks something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>...</title>
</head>
<body>
<applet style="padding:1px; border:1px solid gray" mayscript="mayscript" codebase="..." name="AppletName" code="..." archive="..." width="600" height="500" alt="Alt Text">
<param name="initial_focus" value="true"/>
Alt Text
</applet>
</body>
</html>
When the page initially loads, focus is set in the applet and I can tab through and interact with the applet just fine. However, if I leave the browser window and then come back to it, I can no longer regain focus on the applet just using the tab key.
Pressing F5 to reload the page fixes the page so that the Applet regains focus, but this solution is unacceptable.
How do I solve this problem? Thanks.
Tentative solution:
//Dean Edwards/Matthias Miller/John Resig
function init() {
// quit if this function has already been called
if (arguments.callee.done) return;
// flag this function so we don't do the same thing twice
arguments.callee.done = true;
// kill the timer
if (_timer) clearInterval(_timer);
window.onfocus = function() {
if(!document.AppletName.isActive())
document.AppletName.requestFocus();
};
}
/* for Mozilla/Opera9 */
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", init, false);
}
/* for Internet Explorer */
/*#cc_on #*/
/*#if (#_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
if (this.readyState == "complete") {
init(); // call the onload handler
}
};
/*#end #*/
/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
var _timer = setInterval(function() {
if (/loaded|complete/.test(document.readyState)) {
init(); // call the onload handler
}
}, 10);
}
/* for other browsers */
window.onload = init;
Note that the key part for detecting whether the applet needs focus and requesting it if so is (this only works if mayscript is enabled):
if(!document.AppletName.isActive())
document.AppletName.requestFocus();
The rest of the code is just attaching the window on focus handling after the page is loaded (using the script JQuery.ready is based off of).
Better solutions welcome.