After Login I am able to go this page, here is its HTML, JS & Python code. I want to make multiple choices and afterward, I want to save the choice using save button (input type="submit" onclick="saveVariations()") at the bottom of HTML.
<body>
<tbody>
<tr>
<th scope="row">abc</th>
<td>1</td>
<td>1.0</td>
<td><input type="checkbox" value="abc" onclick="addToVariations(this);"></td>
</tr>
<tr>
<th scope="row">xyz</th>
<td>1</td>
<td>1.0</td>
<td><input type="checkbox" value="xyz" onclick="addToVariations(this);"></td>
</tr>
.
.
.
.
</tbody>
</table>
<input type="button" value="Save variations" onclick="saveVariations()"/>
</body>
Here is the Python code; Giving error I am unable to even find the input tag to process the save button.
from bs4 import BeautifulSoup
import requests
class SessionLogin:
def __init__(self, url_login, login, pwd):
self.ses = requests.session()
login_html = self.ses.get(url_login)
soup_login = BeautifulSoup(login_html.content).find('form').find_all('input')
my_dict = {}
# override the inputs without login and pwd:
my_dict['username'] = login
my_dict['password'] = pwd
self.ses.post(url_login,data=my_dict)
print(type(soup_login))
def get(self, URL):
return self.ses.get(URL).text
url_login = "url"
session = SessionLogin(url_login, "username", "passwoord")
srcr = session.get("url")
print(BeautifulSoup(srcr).find('input'))
Following is the Javascript Code
<script>
var selectedVariations = [];
function addToVariations(cb) {
if (selectedVariations.indexOf(cb.value) > -1) {
selectedVariations.splice(selectedVariations.indexOf(cb.value), 1);
}
else {
selectedVariations.push(cb.value);
}
console.log(selectedVariations);
}
function saveVariations() {
if (selectedVariations.length > 0) {
console.log(selectedVariations);
$.ajax({
type: "POST"
, url: "/dishes/-K9uHK4M-pu9p9yJGl9a/variations"
, data: JSON.stringify(selectedVariations)
, contentType: 'application/json;charset=UTF-8'
, success: function (result) {
console.log(result.Status);
if (result.Status == 200) {
$.notify("Succesfully saved variations!", "success");
window.location.href = "/";
}
else {
$.notify("Something went wrong!", "error");
}
}
});
}
}