Can't submit upload form in Selenium, Page just refreshes - javascript

I am trying to upload an image to instagram's mobile website through selenium. It seems to find the element in question but when I try to submit it, the page merely refreshes.
uploadForm=driver.find_element_by_xpath('//*[#id="react-root"]/section/nav/div/div/form/input')
driver.execute_script("arguments[0].style.height='auto'; arguments[0].style.visibility='visible';", uploadForm)
#makes form visible
submitForm = driver.find_element_by_xpath('//*[#id="react-root"]/section/nav/div/div/form')
#selects whole form
driver.execute_script("arguments[0].style.height='auto'; arguments[0].style.visibility='visible';", submitForm)
#unhides form as well
uploadForm.send_keys("/testman.JPG")
#sends the file path to the input section of form
submitForm.submit()
#attempts to submit form, causing the refresh
Could there be some kind of JS listener preventing me from uploading this way? Here is the code of the form in question

Try doing a .click() on the submit button. Frequently, a dev will put a JavaScript onclick on the button that prevents the default action. You can see the default action for the form when the page "refreshes". The URL will contain your form as query-string parameter.

Related

JS form action link is used instead of link that is actually clicked

I just came accross the below issue in a project of mine:
user clicks a button
a js function is called to check the
input of the form field and if accepted will submit the form to save_to_db.php in an
iframe.
in the iframe, save_to_db.php will save the form details to the db and calls another js function that updates the contents of html elements on the current page showing the latest status.
This used to work without any issues (and still does in most browsers).
But now in Chrome Mobile browser version 63.0.3239 somehow every link a user clicks after they clicked the button, will load to save_to_db.php (the form action of the button) instead of the link that is clicked.
Has anyone noticed this or similiar behaviour or does anyone know how to resolve this?

Submit Lotus Notes XPage form from outside with plain JS

I have a simple Lotus Notes XPage with only an editable RichText dialog that is embedded in a bigger form using an iframe.
The bigger form has a submit button, which triggers some javascript and finally a notes agent which saves all non-richtext values that are inside the bigger form.
Of course the user shall not have to use two submit buttons, so I won't have a (visible) submit button for the XPage. Instead, I want to use javascript to tell the iframe to submit the form.
Using iframe.document.forms[0].submit() does not work - the form is indeed submitted to the Notes server, but XPages won't save the changes I made.
Using a simple XPage button with the action "Save Data Sources", saving works like a charm, but I don't want the user to have to click two buttons in the correct order.
I also tried the following javascript code to fill some invisible fields with the values that IBM submits to the server, but this does not help either:
iframe.document.forms[0].elements["view:_id1:inputRichText1_h"].value = iframe.document.forms[0].elements["view:_id1:inputRichText1"].value;
iframe.document.forms[0].elements["view:_id1:inputRichText1_mod"].value = true;
iframe.document.forms[0].elements["$$xspsubmitid"].value="view:_id1:_id4";
iframe.document.forms[0].elements["$$xspsubmitscroll"].value="0|0";
iframe.document.forms[0].submit();
So now I ask you: how to correctly submit that form content, without the user actually clicking the XPages button? Can I programmatically trigger a click on that button, which would be indifferent from a human actually clicking, except for the human?
have an ordinary div with a fixed id and inside this div have a computedtext that will compute the clientsideid of the "save button" and return that inside the div
and use this clientside js code to do the actual click
var id=iframe.document.getElementById("button").innerHTML
var button=iframe.document.getElementById(id)
button.click()

Javascript form validation not working through LightCMS

So I'm pasting in some code for a form from Salesforce.
This code to be specific: (from the style element to the end of the form) https://gist.github.com/13ab0efd07c2c8cdb3e1
When clicking submit while not filling out any or all fields, I get a form validation check and then a message will popup with the fields that I have not filled out.
However, when I paste the code into our LightCMS template the form validation is not working and just redirects to the thankyou page as if everything went through fine.
They use LightCMS. And even when link to an external js file instead of embedding the js I still get the same results.
I've noticed it adds an "onclick" element on the Submit button on the front-end but it only does that when it's in the CMS not on a bare bones HTML page.
Any thoughts?
i think you should add this
onsubmit=return formvalidator(Document.getElementByid(search-form))
before form action because it will check the form before submitting it. if check fails the action will not occur.

costum redirect after submit

I have this form: http://lawb.co.il/HTMLPage.html
When someone click on the submit button ("שלח טופס" ) they are automaticaly redirected.
How can I prevent this action after clicking on the "שלח טופס" button, or that the page will redirect to a page that I choose and still I will get the information that people fill in the form?
The code is here http://jsfiddle.net/TCpkb/4/
Can you help me with it pleas?
You need to submit using AJAX and then redirect manually to your custom page. If you cannot use JavaScript, there is unfortunately no way to control the redirection if you let the user directly submit the HTML form.

How to submit a form and then have the page refresh to that point on the page

I am trying to figure out a way to submit a form on my site, the form will load the same page, that is action="", after the form has submitted how can I make the page load at the point of the form? Instead of the page loading at the top like it does by default?
set an html anchor and use the anchor notation in the form action "mypage.html#myAnchor"
I don't know for sure if it works after a form post, but maybe you can use an anchor in the action url? (http://www.scribblegraphics.com/articles/articles-anchors.html)

Categories

Resources