Click at a scrollable data table with watir - ruby

Is there anyway of marking several different rows in a scrollable data table ?
I know how to mark one row
b.div(:id, "listProductsForm:productList:bc_4_0").click
I just want to simulate the "Ctrl"- button is pressed down

How does your "scrollable data table" looks like? Show us the HTML. I see that you are using div tag to access one element.
You probably need to fire some JavaScript event. See How to find out which JavaScript events fired?

The chances are good that you will need to use a combination of Watir::IE.send_keys() and the click actions on the document.
Try something like this:
#browser.send_keys("{CTRLDOWN}")
#browser.div(:id, "listProductsForm:productList:bc_4_0").click
#browser.div(:id, "listProductsForm:productList:bc_5_0").click
#browser.send_keys("{CTRLUP}")
Watir API documentation: http://wtr.rubyforge.org/rdoc/1.6.5/classes/Watir/IE.html#M000497
The documentation above links to the specific key commands that can be sent. I'm pretty sure this will require that you have AutoIt installed.

Related

Programmatically Open Link in WebView

I have an NS Window with a WebView.
My program takes in a search query and executes a Google search with it, the results being displayed in the WebView, like a browser.
Instead of displaying the search results in the WebView, I'd like to automatically open the first link and display the contents of that result instead.
As a better example, how do I display the contents of the first result of Google in a WebView?
Is this even possible?
Any help greatly appreciated. Thanks!
You could use the direct Google Search API. That would be more convinient.
https://developers.google.com/custom-search/v1/cse/list?hl=de-DE
Also you could also try to make a google request like the "I'm feeling lucky" button, which will direct you automatically to the first search result.
If you have to parse the HTML, you need to have a look at the HTML structure of the google result page. Look for specific id and class css properties in the div and a tags. If you found the ones, where the actual results are you can start parsing that content. Also i guess it would be easier to put some javascript together, that will find the first result and open it. (More easier than parsing the HTML using obj-c). You can evaluate javascript in the webview using [myWebView stringByEvaluatingJavaScriptFromString: #"put your js code here"].
Sure it is possible.
The first way to accomplish that that goes through my head is to parse the HTML response from Google, then launch a WebView with the first link you extracted.
Take a look at regular expressions to make it easy.

Deleting elements using Watir

Does anyone know how to delete an element from the source using Watir? There doesn't seem to be a method for removing elements. Perhaps I'm missing something.
If you know JavaScript, you could execute any JavaScript code on the page.
Example:
browser.execute_script("some javascript code")
I am not a JavaScript ninja, but this question could help you: JavaScript: remove element by id.
Remove elements by css:
browser.execute_script("[...document.querySelectorAll('.some.class')].map(e => {e.parentNode.removeChild(e)})")
We can remove it with javascript. Here's an example to remove a breadcrumbs div element but it's id:
browser.execute_script("bd = document.getElementById('breadcrumbs'); bd.parentNode.removeChild(bd);")
The Purpose for Watir is to do web testing, which is to say drive the browser as if a user was interacting with it. That means doing the things a user could do, clicking on stuff, filling in input fields, etc. It also means being able to verify what is there on the screen that the user can see or interact with.
Since a user cannot delete elements, there is no means by which to do that using the tool.
If the application provides a way for users to 'remove' or 'delete' something, like closing a simulated window, removing a tab etc, then you need to do that by simulating what the user would do (usually clicking on some specific element) in order for that to happen.

Backbone.js - don't render view/template again

In my app I have a list of products and when you click on a product, a Fancybox opens to show the product details.
Now when the user closes the Fancybox, I change the URL back from '#/product-name' to '#' and the list of products is rendered again, even though it is already there.
My question is:
How do I avoid the product list from being rendered again?
So somewhere either in the list action of my controller or the list view I want to check if the product list is already rendered and don't render it again.
It feels like something that should be possible to accomplish quite easily but I can't get it right.
All ideas appreciated!
EDIT: edited for clarification
Have a look at backbone:s saveLocation method. It doesn't trigger a hashchange event.
You only need to change the hash part of your url.
window.location.hash = ""

How can I show related links dynamically without performing a page postback?

I want to create Stack Overflow-like question asking functionality.
I have noticed as soon as the cursor is moved from Title textbox to Question, it is showing related links, without doing a page postback. I want to do something similar to that.
How can I perform this?
Use ajax.
When the title loses focus, use an ajax call to get related info and then show the results.
Also, use jquery!
A useful library when dealing with AJAX.

Change appearence of page dynamically like twitter or tumblr

I'm trying to find tutorials or code to allow users to customise their page, just like twitter ,wordpress and tumblr do.
Could someone tell me what technology their using?
i'm a .net developer, but maybe they're using jquery?
Any help would be great.
Thanks
You can use javascript to change style sheets and the DOM
Question is a bit broad. To change the page you simply need to manipulate the DOM or change the CSS associated with the page's elements. This can be done any number of ways. E.g. you could write out a new CSS class dynamically, you could add new elements to the DOM itself or you could modify the existing attributes of the page. e.g. to set the background of the page you can do something like:
(assuming JQuery)
$("body").css('background-image','url(path/to/image)');
Hope that helps,
-fs

Resources