My HTML looks like below
<div class="container">
<div class="jumbotron">
<h1 id="survey-title" class="display-5 text-capitalize">Your favourite candidate</h1>
<hr class="my-4">
<div class="card-body">
<h5 id="question-title" class="card-title">What is your name?</h5>
<form id="question_form" action="/survey/takesurvey/1/2" method="post" class="form">
<input type="hidden" name="csrfmiddlewaretoken" value="ELBWYGZRxRuI7CoZ2xkmgCJ3f9JweFMM4Ew1pQbgSE3BLb38VStPJEbHvsyiBEFg">
<div class="form-group"><input type="text" name="response" value="asdfasdfas" maxlength="400" class="form-control" title="" id="id_response"></div>
</form>
</div>
<a id="btn-previous" href="javascript:history.back()" class="btn btn-primary ">Previous</a>
<a id="btn-next" href="/survey/takesurvey/finish/1" class="btn btn-primary">Next</a>
</div>
</div>
Notice the href
on previous button
<a id="btn-previous" href="javascript:history.back()" class="btn btn-primary ">Previous</a>
Clicking next will submit form and go to "next" page, again clicking "previous" should come back and preserve the input value in previous page. I am using following code to test this behavior, The following code is working only when I put sleep(1)
line in between finding the element and clicking. Else the page is not going back (url not changing)
- Why just waiting for url change before clicking the button not working
- I suspect it has to do with javascript event handler (which is inline in html) not being loaded.
- I is there any way to check if page is ready for the click event
cur_url = self.browser.current_url
self.browser.find_element_by_id('btn-next').click()
wait(lambda: self.assertNotEqual(self.browser.current_url, cur_url))
btn_previous = self.browser.find_element_by_id('btn-previous')
## This code is not working without the sleep below. Which I suspect
## has to do with javascript event handler (which is inline in html) not being loaded.
## Is there better way to check that the button is ready to be clicked
sleep(1)
btn_previous.click()