I'm currently doing some task for my university. I'm writing Django Selenium tests for my app. I'm trying to write test for deleting object.
They key parts of my code are:
delete confirmation.html
<form action="" method="post" id="confirmForm">{% csrf_token %}
<p>{% trans "Are you sure you want to delete this car?" %}</p>
<input class="center-block btn btn-danger" type="submit" value="{% trans 'Confirm' %}"/>
</form>
modal.js
function showModal(url) {
$("#myModalBody").text();
$("#myModal").modal();
$.ajax({
url,
cache: false
}).done(function (html) {
$("#myModalBody").html(html);
$("#confirmForm").attr('action', url);
});
}
When I click following button
<button class="btn btn-primary btn-sm pull-left" value="" id="car-delete-modal-btn m-10-b" onclick="showModal('{% url 'c2crental:delete_car' details_car.id %}');">{% trans "Delete car" %}</button>
And test stops with result: Unable to locate element. I was trying to use different selectors but none of them worked. For now test looks like this:
# click 'delete' button to display popup confirmation window
delete_btn = self.selenium.find_element_by_id('car-delete-modal-btn m-10-b')
delete_btn.click()
# click 'confirm' to delete object in popup window
submit = 'input[type="submit"]'
confirm_btn = self.selenium.find_element_by_id(submit)
confirm_btn.click()
I just can't seem to find proper selector for this button or it's a problem with a synchronization. Can someone help me fix it?
Sorry for my broken english and i hope you will understand what I'm trying to do here but I'm just starting with Django, tests, programming in general so not everything is clear.