Python 3.x selenium chromedriver在Python中提交表单时出现的问题

Python 3.x selenium chromedriver在Python中提交表单时出现的问题,python-3.x,selenium-webdriver,xpath,web-scraping,selenium-chromedriver,Python 3.x,Selenium Webdriver,Xpath,Web Scraping,Selenium Chromedriver,我已经检查了多个类似的问题和答案,但不幸的是没有找到任何解决我的具体情况 问题描述 我正在试着填写并提交表格。表单的构建如下所示: <form id="hikuZR" action="/historische-kurse/BMW" method="post"> ... <div class="hidden"><input type="submit" value="senden"></div> <span class="button bgBlu

我已经检查了多个类似的问题和答案,但不幸的是没有找到任何解决我的具体情况

问题描述

我正在试着填写并提交表格。表单的构建如下所示:

<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>
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')
这部分工作正常,我能够将所有值放入表单:

点击按钮:

我还试图通过XPATH定位按钮:

hist_button = self.driver.find_element_by_xpath("//span[contains(.,'Historische Kurse anzeigen')]")
点击这个按钮,似乎可以找到:

这对我不起作用。我也尝试过通过执行一些答案中建议的脚本来执行按钮,因此:

self.driver.execute_script("arguments[0].click();", hist_button)
而且这个解决方案在我的情况下不起作用。页面已刷新,但未显示历史日期的结果:

这是我在手动点击按钮后看到的:

你能帮我找出我做错了什么吗?多谢各位

更新日期:2018年2月25日

正如注释中所建议的,我正在使用Select类从下拉列表中选择值,如下所示:

<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>
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')
我在表单中看到了选定的值(在描述中发布了“第一个”版本,我也在表单中看到了值)。之后,我再次点击按钮,没有任何效果。页面已刷新,但我看不到结果:

hist_button = self.driver.find_element_by_xpath("//span[contains(.,'Historische Kurse anzeigen')]")
hist_button.click()
html_historical = self.driver.page_source


当我手动单击按钮时,所选数据的结果将正确显示。看起来按钮的执行不起作用

问题在于,您的代码没有更改下拉列表的值,当您使用默认值单击按钮时,日期范围是从今天到今天,并且没有返回值。请看下面描述的从下拉列表(
select
element)中选择值的正确方法,相应地设置值,然后单击按钮,您应该会得到结果。@JeffC:谢谢您的建议。我正在尝试从下拉列表中选择:
start_day_1=Select(self.driver.find_element_by_xpath(“//Select[@name='inTag1']”)start_day_1。选择_by_value(“22”)
,然后按问题中所述单击按钮,没有任何效果。我仍然无法看到所选值的结果。我还错过了什么吗?谢谢用您当前的代码注明问题日期,以便我们查看。你看到值在更新吗?e、 g.22现在显示在下拉列表中?@JeffC我已经更新了问题,是的,我在表格中看到了所选的值。谢谢。问题是你的代码没有改变下拉列表的值,当你用默认值点击按钮时,日期范围是从今天到今天,没有返回值。请看下面描述的从下拉列表(
select
element)中选择值的正确方法,相应地设置值,然后单击按钮,您应该会得到结果。@JeffC:谢谢您的建议。我正在尝试从下拉列表中选择:
start_day_1=Select(self.driver.find_element_by_xpath(“//Select[@name='inTag1']”)start_day_1。选择_by_value(“22”)
,然后按问题中所述单击按钮,没有任何效果。我仍然无法看到所选值的结果。我还错过了什么吗?谢谢用您当前的代码注明问题日期,以便我们查看。你看到值在更新吗?e、 g.22现在显示在下拉列表中?@JeffC我已经更新了问题,是的,我在表格中看到了所选的值。谢谢
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