I've checked already multiple similar questions and answers, but unfortunately didn't found any solution for my particular case.
Issue description
I'm trying to fill out and submit the form on this site. The form was build as follow:
<form id="hikuZR" action="/historische-kurse/BMW" method="post">
...
<div class="hidden"><input type="submit" value="senden"></div>
<span class="button bgBlue btn-xs-block pull-sm-right" onclick="submitForm($(this));">Historische Kurse anzeigen</span>
</div>
<input type="hidden" name="pkBHTs" value="1550956687">
</form>
This is how I'm performing it:
Filling out the form
start_day_1 = self.driver.find_element_by_xpath("//select[@name='inTag1']/option[@value=22]")
start_day_1.click()
start_day_2 = self.driver.find_element_by_xpath("//select[@name='inTag2']/option[@value=22]")
start_day_2.click()
start_month_1 = self.driver.find_element_by_xpath("//select[@name='inMonat1']/option[@value=08]")
start_month_1.click()
start_month_2 = self.driver.find_element_by_xpath("//select[@name='inMonat2']/option[@value=08]")
start_month_2.click()
start_year_1 = self.driver.find_element_by_xpath("//select[@name='inJahr1']/option[@value=2018]")
start_year_1.click()
start_year_2 = self.driver.find_element_by_xpath("//select[@name='inJahr2']/option[@value=2018]")
start_year_2.click()
try:
market = self.driver.find_element_by_xpath("//select[@name='strBoerse']/option[@value='%s']" % 'XETRA')
market.click()
sleep(randint(7, 10))
except NoSuchElementException:
print("Element by xpath does not exist!")
This part works fine, and I'm able to put all values to the form:
Clicking on the Button:
I'm trying to locate the button by XPATH as well:
hist_button = self.driver.find_element_by_xpath("//span[contains(.,'Historische Kurse anzeigen')]")
and to click on this button, which seems to be found:
hist_button.click()
It doesn't work for me. I've tried also performing the button by executing the script as proposed in some answers on SO:
self.driver.execute_script("arguments[0].click();", hist_button)
Also this solution doesn't work in my case. The page has been refreshed, but didn't show me the result for the historical dates:
This is what I see after manual clicking on the button:
Could you please help me to find out, what I'm doing wrong? Thank you.
Update 25.02.2018
As suggested in the comment, I'm selecting the values from DropDown lists with the Select class as follow:
start_day_1 = Select(self.driver.find_element_by_xpath("//select[@name='inTag1']"))
start_day_1.select_by_value("22")
start_day_2 = Select(self.driver.find_element_by_xpath("//select[@name='inTag2']"))
start_day_2.select_by_value("22")
start_month_1 = Select(self.driver.find_element_by_xpath("//select[@name='inMonat1']"))
start_month_1.select_by_value("8")
start_month_2 = Select(self.driver.find_element_by_xpath("//select[@name='inMonat2']"))
start_month_2.select_by_value("8")
start_year_1 = Select(self.driver.find_element_by_xpath("//select[@name='inJahr1']"))
start_year_1.select_by_value("2018")
start_year_2 = Select(self.driver.find_element_by_xpath("//select[@name='inJahr2']"))
start_year_2.select_by_value("2018")
market = Select(self.driver.find_element_by_xpath("//select[@name='strBoerse']"))
market.select_by_value('XETRA')
And I'm seeing the selected values in the form (with the "first" version posted in the description, I saw the values in the form as well). After that I'm clicking the button again without any effects. The page was refreshed, but I don't see the results:
hist_button = self.driver.find_element_by_xpath("//span[contains(.,'Historische Kurse anzeigen')]")
hist_button.click()
html_historical = self.driver.page_source
or
hist_button = self.driver.find_element_by_xpath("//span[contains(.,'Historische Kurse anzeigen')]")
self.driver.execute_script("arguments[0].click();", hist_button)
html_historical = self.driver.page_source
When I click on the button manually, the result for selected data will show correctly. It looks like the performing of the button is not working.