Get and set focus position in SWT browser - java

I want to get and set the position within a SWT browser but I don't know how.
First, I created a browser control:
Browser browser = new Browser(shell, SWT.NONE);
Then I launched a HTML document:
File file = new File("C:\\test\\index.html");
browser.setUrl(file.toURI().toString());
That works perfect so far.
Now I scroll down the page to find an interesting text passage and click a menu item to create a kind of bookmark.
My question is: How can I get the current focus position (x,y) to remember the point in the text and how can I reset the position later to "apply" a specific bookmark?

You can interact with the browser content through Browser#evaluate() and Browser#execute().
Both methods allow to execute Javascript in the context of the browsers document.
To send Javascript code that queries the current position, use something like:
Object position = browser.evaluate( "window.getCurrentPosition();" );
The type of the return value depends on the code that is evaluated. Debug through the code to see what the actual return type is.
If you aren't interested in the return value, use execute. For example to set the current position you would use:
browser.evaluate( "window.setCurrentPosition( x, y );" );
Please note that the Javascript is pseudo-code and doesn't actually return the current position.
If you run into SWTExceptions, it is likely that the document isn't fully loaded yet and you need to delay the execution of the Javascript code until it is fully loaded as explained here:
https://stackoverflow.com/a/7802717/2986905

Related

how do I find the end of the scroll bar using Java in RFT

My application has the web page, which is longer than the browser size. This needs the application shld be scrolled down to view the complete Web page. I need to know how do I find the end of the Web Page unsing Java in RFT code?
Is there some special object in your page footer? Like an image or a particular link? You can continue to scroll down until it becomes visible.
This is some sample code using LowLevelEvents, scrolling down with the mousewheel instead of dragging the scrollbar:
while(!your_object.isVisible()) {
LowLevelEvent llEvents[] = new LowLevelEvent[1];
llEvents[0] = MouseWheel(-25)
getRootTestObject().emitLowLevelEvent(llEvents);
}
Some docs: PlayingBackLowLevelMouseandKeyboardActions
If your_object.isVisible() always returns true, you can click on an object at the end of the page; this will browse the page to its and.
If there is no object clickable, you can press "END" to scroll to the end. Use browserObject.inputKeys method for this.

How to verify if Tab on Web Page is selected using Selenium RC..?

How to verify if Tab on Web Page is selected using Selenium RC
I wanted to one very simple thing. Does anyone know using selenium RC Python Client how I can know if a Tab is selected on web page?
By tab I mean the following examples from the following link-
http://esdi.excelsystems.com/wsexmp/DIVTAB.pgm?wsnum=00096
I have used focus(), isSomethingSelected(), isVisible() but didn't get the solution.
I need to verify that the specific tab is selected by default after webpage opens. Isn't there a method like is_tab_selected(tab_locator)??
please provide the clear solution pls..
I have used focus(), isSomethingSelected(), isVisible() but didn't get
the solution.
These methods use the common HTML element terminology.
focus() is for elements that are focused, meant as when you click a focusable element, it has a focus on it. To see what I mean, you can loop through the focusable elements on your page via pressing the Tab key repeatedly. This changes focus.
is_something_selected() is for selecatble <option> elements (which are the children of a <select> element)
is_visible() tells you whether an element is actually visible on the page or whether it is hidden via CSS.
Anyway, there's no is_tab_selected(tab_locator) method, because there's no such thing as a tab. In your case, your "tabs" are just simple clickable <a> elements which have a class attribute tab-active or tab-disabled based on their state.
Therefore, if you wanted, for example, to know whether the second tab is active, you would do
is_element_present("css=#tab2.tab-active")
This will return either true or false based on whether the tab is selected or not.
Or the other way around, if you wanted to know which tab is currently active, you would do:
get_attribute("css=.tab-active#id")
This will return the id of the selected tab.
You have to find a unique tag in your webpage. You can do
driver.findElement(By.xpath(".//tagname"))
If the above line doesn't throw any exception, you can confirm that you are located in your webpage.

Initialise Google Motion chart with log axis

I am not sure if this is the place to ask, but I saw another question about google motion charts here, so here I go...
I have javascript that creates a chart, I don't initialise a state, but I read here how to do that.
My question is, how do I start the chart with logaritmic axis? I haven't found any documentation about this. Perhaps I have overlooked something. Thanks for any ideas!
Got it. Follow these steps:
Open a working chart and set the settings that you'd like to capture. Settings you can specify include opacity levels, zooming, and log vs linear scaling.
Open the Settings panel by clicking the wrench symbol in the lower right corner of the chart.
Click the Advanced link in the lower left corner to add the Advanced panel to the set.
Expand the Advanced panel and copy the contents of the State text box to your clipboard. (Note: instead of using the menu, described in steps 2—4, you could insert a button on your page that calls getState() and displays the current state in a message box.)
Assign the state string that you copied in the previous step to the "state" options parameter in your code, as shown here. When passed into the draw() method, the chart will be initialized to the state specified on startup.
I think the log/lin refers to the parameter xAxisOption: 2.
Somewhere in the beginning of the code, paste this (and replace the state with your clipboard content):
var options = {};
options['state'] ='{"duration":{"multiplier":1,"timeUnit":"D"},"yLambda":0,"yZoomedIn":false,"showTrails":true,"dimensions":{"iconDimensions":["dim0"]},"uniColorForNonSelected":false,"nonSelectedAlpha":0.4,"xAxisOption":"2","iconKeySettings":[],"xZoomedDataMin":18.75546,"time":"1985-02-12","colorOption":"4","xZoomedDataMax":1133.55129,"orderedByX":false,"orderedByY":false,"xLambda":0,"playDuration":15000,"iconType":"BUBBLE","yAxisOption":"3","yZoomedDataMin":-32.736,"xZoomedIn":false,"yZoomedDataMax":-1.166,"sizeOption":"5"};';
Then comes the chart data and in the end:
options['width'] = 760;
options['height'] = 480;
chart.draw(data, options);

GWT. Window.Open method is not working in loops

I have a problem with GWT method Window.Open. It works normally when I want to open one window. But, when I need to open two or more URL's in a new window, it opens only one. And in a new window always shows last url in list.
for (RoomReservation reservetion : roomReservationListModel.getRoomReservationsList()) {
Window.open(reservetion.getPrintoutUrl(), L10n.getMessages().print(), HtmlCssElementNames.BLANK);
}
Second param without white spaces.
The second argument to Window.open is window's name, not its title (that one is given by the document showing inside). It's used as the target="" for links and forms, among other things, and uniquely identifies the window (or frame or iframe).
You're using the same value each time, so you're reusing the same window for all the URLs.
Use _blank as the second argument to make sure you always open a new window, without the risk to reuse an existing one.

Dragging, Dropping & resizing elements

I have a web page which has three <div> elements:
Right_bar contains several layouts (nothing to do with this question)
Bottom_bar contains several components e.g. calculator, logo, a group of buttons etc. each component uses a <div> and must be resizable and draggable.
And a Working Area, where all the components are dropped & resized. Also a user can resize & change the location of components anywhere in the Working Area. Once a user sets a component then the page must be saved in same style and it shouldn't be changed even after refreshing the page.
My questions are:
Should I use a database to save the location of component.
Which one should I use: JQuery / AJAX / anyother?
If you know of any tutorials please let me know although I am beginner in JavaScript, Basically a Java programmer.
Note: on the server side I am using Servlet.
Whenever the user drops an element, launch a simple Ajax request that will pass the new value to the server.
try {
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // IE
}
catch(e)
{
var xmlhttp = new XMLHttpRequest(); // Other browsers
}
xmlhttp.open('GET', 'yourServerScript.url?param=value', true);
xmlhttp.send(null);
You may want to check if the request succeeded or failed by handling the "readystatechange" event of your http request, but that doesn't seem important in your case.
After that you just have to get the value server-side, store it in a session variable, and then on every page load, check if there is a session variable defined for the parameter before setting it to its default value.
What you can do is save the location of the control in a xml and save it in a table.
2.jquery UI has as build in framework that supports drag and drop div elements, check this link http://jqueryui.com/demos/droppable/
I did the same thing for an application. (but I used PHP, anyway it doesn't matter for what you need)
I used jQuery + jQuery UI drag & drop / resize
I used AJAX with 4 parameters (x,y, z-index and id of the element) for drag & drop on drag stop
I used XML as a database for this, but any database (or any persistance way) will do the trick. As #Thibault Witzig said, take the most pertinent for your project.

Categories