javascript get a query string that a form will submit
If you have a form, like
<form id='testform' method="post" action="/" />
<input name="test1" value="yes" type="text">
<input name="test2" value="no" type="text">
</form>
Is there a way to get the query string that this form would submit? (without knowing anything about what fields are inside it) test1=yes&test2=no
or just the same thing in json format?
I am using selenium, so could do it either on the selenium side run javascript in the browser.
const form = await driver.findElement(By.id('testform'));
.. now do something in selenium to find out the request post request
or in the browser
const form = document.getElementById('testform');
... somehow get the query string or request info
any ideas?
javascript html forms selenium
add a comment |
If you have a form, like
<form id='testform' method="post" action="/" />
<input name="test1" value="yes" type="text">
<input name="test2" value="no" type="text">
</form>
Is there a way to get the query string that this form would submit? (without knowing anything about what fields are inside it) test1=yes&test2=no
or just the same thing in json format?
I am using selenium, so could do it either on the selenium side run javascript in the browser.
const form = await driver.findElement(By.id('testform'));
.. now do something in selenium to find out the request post request
or in the browser
const form = document.getElementById('testform');
... somehow get the query string or request info
any ideas?
javascript html forms selenium
Do you actually need the string of data or just to send it somewhere, eg through ajax? If the latter you can use FormData to grab all of a form's input fields and send through ajax directly
– Patrick Evans
Nov 21 '18 at 16:37
Do you want just a string from all input fieldsname-value
pairs?
– Andersson
Nov 21 '18 at 16:55
yeah - string, or object
– Alex028502
Nov 21 '18 at 17:06
I'm need it in selenium, but so if selenium had a way to do it that would be best, but if there is a way to get it in the browser, I can just useexecuteScript
.
– Alex028502
Nov 21 '18 at 17:07
add a comment |
If you have a form, like
<form id='testform' method="post" action="/" />
<input name="test1" value="yes" type="text">
<input name="test2" value="no" type="text">
</form>
Is there a way to get the query string that this form would submit? (without knowing anything about what fields are inside it) test1=yes&test2=no
or just the same thing in json format?
I am using selenium, so could do it either on the selenium side run javascript in the browser.
const form = await driver.findElement(By.id('testform'));
.. now do something in selenium to find out the request post request
or in the browser
const form = document.getElementById('testform');
... somehow get the query string or request info
any ideas?
javascript html forms selenium
If you have a form, like
<form id='testform' method="post" action="/" />
<input name="test1" value="yes" type="text">
<input name="test2" value="no" type="text">
</form>
Is there a way to get the query string that this form would submit? (without knowing anything about what fields are inside it) test1=yes&test2=no
or just the same thing in json format?
I am using selenium, so could do it either on the selenium side run javascript in the browser.
const form = await driver.findElement(By.id('testform'));
.. now do something in selenium to find out the request post request
or in the browser
const form = document.getElementById('testform');
... somehow get the query string or request info
any ideas?
javascript html forms selenium
javascript html forms selenium
asked Nov 21 '18 at 16:27
Alex028502Alex028502
1,270719
1,270719
Do you actually need the string of data or just to send it somewhere, eg through ajax? If the latter you can use FormData to grab all of a form's input fields and send through ajax directly
– Patrick Evans
Nov 21 '18 at 16:37
Do you want just a string from all input fieldsname-value
pairs?
– Andersson
Nov 21 '18 at 16:55
yeah - string, or object
– Alex028502
Nov 21 '18 at 17:06
I'm need it in selenium, but so if selenium had a way to do it that would be best, but if there is a way to get it in the browser, I can just useexecuteScript
.
– Alex028502
Nov 21 '18 at 17:07
add a comment |
Do you actually need the string of data or just to send it somewhere, eg through ajax? If the latter you can use FormData to grab all of a form's input fields and send through ajax directly
– Patrick Evans
Nov 21 '18 at 16:37
Do you want just a string from all input fieldsname-value
pairs?
– Andersson
Nov 21 '18 at 16:55
yeah - string, or object
– Alex028502
Nov 21 '18 at 17:06
I'm need it in selenium, but so if selenium had a way to do it that would be best, but if there is a way to get it in the browser, I can just useexecuteScript
.
– Alex028502
Nov 21 '18 at 17:07
Do you actually need the string of data or just to send it somewhere, eg through ajax? If the latter you can use FormData to grab all of a form's input fields and send through ajax directly
– Patrick Evans
Nov 21 '18 at 16:37
Do you actually need the string of data or just to send it somewhere, eg through ajax? If the latter you can use FormData to grab all of a form's input fields and send through ajax directly
– Patrick Evans
Nov 21 '18 at 16:37
Do you want just a string from all input fields
name-value
pairs?– Andersson
Nov 21 '18 at 16:55
Do you want just a string from all input fields
name-value
pairs?– Andersson
Nov 21 '18 at 16:55
yeah - string, or object
– Alex028502
Nov 21 '18 at 17:06
yeah - string, or object
– Alex028502
Nov 21 '18 at 17:06
I'm need it in selenium, but so if selenium had a way to do it that would be best, but if there is a way to get it in the browser, I can just use
executeScript
.– Alex028502
Nov 21 '18 at 17:07
I'm need it in selenium, but so if selenium had a way to do it that would be best, but if there is a way to get it in the browser, I can just use
executeScript
.– Alex028502
Nov 21 '18 at 17:07
add a comment |
1 Answer
1
active
oldest
votes
Thanks Patrick,
const formFields = await driver.executeScript('return Array.from(new FormData(document.getElementById("testform")))');
works great.
I guess if anybody needs to do this without selenium it's just
Array.from(new FormData(document.getElementById("testform")))
or look at the other ways you can cycle through the FormData
object.
Then you can turn that into a query string if that is what you need.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416500%2fjavascript-get-a-query-string-that-a-form-will-submit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks Patrick,
const formFields = await driver.executeScript('return Array.from(new FormData(document.getElementById("testform")))');
works great.
I guess if anybody needs to do this without selenium it's just
Array.from(new FormData(document.getElementById("testform")))
or look at the other ways you can cycle through the FormData
object.
Then you can turn that into a query string if that is what you need.
add a comment |
Thanks Patrick,
const formFields = await driver.executeScript('return Array.from(new FormData(document.getElementById("testform")))');
works great.
I guess if anybody needs to do this without selenium it's just
Array.from(new FormData(document.getElementById("testform")))
or look at the other ways you can cycle through the FormData
object.
Then you can turn that into a query string if that is what you need.
add a comment |
Thanks Patrick,
const formFields = await driver.executeScript('return Array.from(new FormData(document.getElementById("testform")))');
works great.
I guess if anybody needs to do this without selenium it's just
Array.from(new FormData(document.getElementById("testform")))
or look at the other ways you can cycle through the FormData
object.
Then you can turn that into a query string if that is what you need.
Thanks Patrick,
const formFields = await driver.executeScript('return Array.from(new FormData(document.getElementById("testform")))');
works great.
I guess if anybody needs to do this without selenium it's just
Array.from(new FormData(document.getElementById("testform")))
or look at the other ways you can cycle through the FormData
object.
Then you can turn that into a query string if that is what you need.
answered Nov 22 '18 at 9:37
Alex028502Alex028502
1,270719
1,270719
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416500%2fjavascript-get-a-query-string-that-a-form-will-submit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you actually need the string of data or just to send it somewhere, eg through ajax? If the latter you can use FormData to grab all of a form's input fields and send through ajax directly
– Patrick Evans
Nov 21 '18 at 16:37
Do you want just a string from all input fields
name-value
pairs?– Andersson
Nov 21 '18 at 16:55
yeah - string, or object
– Alex028502
Nov 21 '18 at 17:06
I'm need it in selenium, but so if selenium had a way to do it that would be best, but if there is a way to get it in the browser, I can just use
executeScript
.– Alex028502
Nov 21 '18 at 17:07