I am testing a JQuery Web application. I have a JQuery popup that I simply cannot get the submit button to fire in Watir. The same pattern is used thought the application.
I have verified the button exists and have tried click, fireEvent you name it and am out of methods to call.
Has anyone solved this?
Which do you want ?
A. Control cursor and click "submit"
or
B. Simula te click "submit"
A:need to use Autoit and control cursor and click ,but only for windows OS. B:execute the javascript that when clicking "submit".
If B case,there is two ways I used always.
1.execute that code in URL-bar.
ex.) #ie.link(:URL, 'javascript:<-CODE->;').click
or
Make like that module and use it by include in test case.
ex.) #ie.excute_script(<-CODE->)
module Watir
class IE
def execute_script(scriptCode)
WIN32OLE.codepage = WIN32OLE::CP_UTF8
window.execScript(scriptCode)
end
def window
WIN32OLE.codepage = WIN32OLE::CP_UTF8
ie.Document.parentWindow
end
end
Maybe...
I hope it help.
Sorry my poor english.
tknv/
In my case the solution was to use and index value of 1. JQuery creates a copy of the form and all the popup items have an index of 1. The 0 index controls are on the original form.
I just had the same problem. Ajax upload for jQuery demo is an example page. I want to upload a file using Upload button on the left hand side of the page.
When I click Upload button by hand, file upload pop up appears.
When I click the button with Watir, nothing happens.
Gary (accepted answer) helped me to find a solution:
browser.file_field(:index, 1).set "/path/to/file"
Related
I'm trying to check if a button was pressed and then open a new html file, I'm using express.js app.get method to open all of my HTML files. So my question is how can I open a HTML file on the same window when I press a button?
You could but shouldnt. NodeJS is backend.
Also note, that NodeJS is no JavaScript as normally referred to.
It is written/programmed in JavaScript.
To do something on click you would need either a normal <a> tag if you just want to open a link or you use client-side JavaScript with an onlick handler to execute something after a user clicked on an element.
You can accomplish this using javascript embedded into the html like this:
<button onclick="window.location='http://google.com'">Click me</button>
you can also try window.open=url
please note that this isn't really using node, just javascript. this type of behavior belongs in the page.
I think this thread would help you :)
https://stackoverflow.com/a/33703429/4578393
it uses if statements to check if the button has been pressed
if(req.body.hasOwnProperty("butt1")){
console.log("butt1 clicked");
Taine
I am trying to create an adhoc code that save me pressing a repetitive button on a webpage, I opened F12 developer and tried using getElementbyID(..).click(); however didn't quite work, this is part extract of the button, I wonder if someone can advise what code I can use to automatically submit the button? Any help will be greatly appreicated. Best regards, Jon
what code I can use to automatically submit the button
If this is for a regular form post without AJAX then you can select the form then use submit().
E.g.
/*
* The variable myform is previously determined such as by `document.forms[0]`
* or a similar DOM selector method
*/
myform.submit();
If this is for a non-form button then use the click() method as suggested in the comments above. However, be aware that for this method there would have to be an Event Listener attached for the button to do anything of value.
I have a fragment page (jsff) with a numeric keyboard based on buttons surrounded by a client listener which invoke a java script function; every time I click a number it refresh an input text with the value concatenated. I implemented that with JavaScript. Why with JavaScript? Because of the delay using partial triggers showing the value in the input text.
When I test it in the server it works very fine. I click every button and do have a little delay, but It works for the requirements of the develop.
Now, when I insert that fragment inside another jsff which have several components, the result isn't the same. I click every button, and the value is displayed in the input text very fast, but, the button I clicked takes between one and two second to reload for been clicked again. I don't understand what is happening.
Could anyone help me?
Thank you very much.
In Oracle Community I was helped by Florin Marcus:
I quote the answer that works for me:
"Probably you are still propagating the event to the server. You can easily double-check this with a browser plugin like Firefox/Firebug, see if there is any server request being sent.
Normally, you will need to explicitly cancel the event from propagating to the server. For example, if you have a clientListener on a button, you do something like below:
function showPopupFromAction(actionEvent)
{
actionEvent.cancel();
//your logic here
}
"
Can someone please explain how can I go about creating the following page and what techniques should I adopt:
The user should be able to click on a button which should result in a popup.
The popup should have a static page with instructions and button to click which takes the user to the next step in the same popup.
At the next step the functionality should run to take input from the user and save it to the server.
The user should see a confirmation finally and on clicking finish, the popup should hide.
From what I understand, I should try the following:
use javascript onclick and fadeIn function to create the popup.
continue changing the same div using onclick and AJAX to create stepwise kind of a format and carry out the functionality.
use XMLHTTPRequest to upload data acquired and finally use fadeOut to hide the popup.
The reason why I am thinking in these lines is because I have had very little exposure to web designing and hence would love to get some expert views on if this is the right approach and if not then what should be a better way to do it. Is there is some existing literature/method which talks about it?
Any help would be much appreciated.
For first step
Use javascript onclick function. But before this keep your static content ready and than use jQuery UI to appear it as good Dialog Box. For example see this
For second step
The user will never know that you have changed the dialog. Just you can load new dialog with new content in it. When you click button on first page, make that first dialog box is closed.
For third step
Instead of static content make the response set to dialog, here you may use Ajax/post call.
Las step
Its not compulsion to use XMLHTTPRequest. You can even submit form in jQuery post/ajax. Than you can reload the page with confirmation message send in response from server or you may use jQuery to make the confirmation message appear.
I have a page that will cause an error if a user tries to click too many buttons at one time (for the impatient user) and therefore need to DISable any button (all defined by a JS onclick function) on the page until it is refreshed (with new data sent via the server using Java.) What is the best method to do this, and is there a way to do it with jQuery?
You would have to find all types of buttons using something like this..
$('input[type="submit"], button')
and loop through the returned array and do .attr('disabled','disabled'); on the item in each iteration.
How about simply calling this when you want to disable the buttons:
jQuery('input[type="button"]').attr('disabled', 'disabled');
That will disable all inputs of type button on the page. Of course, as soon as you reload/replace the page contents, the new buttons will not be disabled. You can also just disable all inputs if that's easier.
Fiddle: http://jsfiddle.net/duffmaster33/xDMux/
The single best solution is to use the BlockUI plugin for jQuery. It accomplished everything I needed and more. http://www.malsup.com/jquery/block/