Submitting forms and page navigation using javascript executor

118 views
Skip to first unread message

Don Henton

unread,
Nov 5, 2014, 10:00:32 AM11/5/14
to seleniu...@googlegroups.com
I've searched this group with 'javascript form submission' but didn't find anything relevant. I've got a complicated form that doesn't have a submit button; its submitted by clicking on an icon. and When using selenium form.submit() it fires but its empty. Apparently there is a lot of javascript that preps the form first, via jquery widget code.  WebElement click doesn't submit the form either.


I'm headed toward trying to understand the jquery widget code and prep the form first, but before I do that I was hoping to ask the following.

Here is the javascript that I'm trying to run:

var sClick = document.createEvent('MouseEvents');
 sClick.initMouseEvent('click', true, false, window, 1, arguments[1], arguments[2], arguments[1], arguments[2], false, false, false, false, 0, null); $(arguments[0])[0].dispatchEvent(sClick); 
 
argument[0] cssSelector
argument 1 and 2 window relative coordinates

where the arguments are for the executeScript method. The corresponding code will work correctly when submitted to the Firefox console, which is the browser used by my driver.

Is it my luck that you can't navigate off a page in javascript via the Executor? Is there some basic rule that says you can't submit a form or leave a page under javascript? I know that you can issue a browser back js command, but am I missing somehting obvious?

Thanks for any help!
Message has been deleted

David

unread,
Nov 6, 2014, 5:21:33 PM11/6/14
to seleniu...@googlegroups.com
Does the JS code work when you run it under Selenium? If not, describe what happens instead.

I know that using JS to "mouse" click an item (link, button) that loads a new page works. I've never done JS mouse click over coordinates though, just to a specific element.

Also, if you are using mouse click, you may also want to see if using the Actions class for native Selenium API mouse click works for you or not as well.

FYI, I've also found JS mouse click better than native Selenium WebElement.click() in some cases, like when the native click doesn't take effect or the native click causes a page load that somehow seems to get stuck. Using JS mouse click in those cases, it takes effect and does not block, loading the page right away. 
Reply all
Reply to author
Forward
0 new messages