首页 > 解决方案 > 无法在 Python Selenium 上提交/单击/执行 Javascript WebForm

问题描述

我想在填写 From 和 To 日期后单击 Search 按钮。然后,框下方的交易将刷新以显示过滤后的交易。它只是不会过滤交易。我无法让 Selenium 单击“搜索”按钮。我尝试了很多方法(请参阅下面我尝试执行的代码和屏幕截图)但没有成功。

任何帮助,将不胜感激。

<div class="ButtonPanel">
    <div class="left">
      <a id="ctl00_BodyPlaceHolder_lbCancel" class="button button_ui button_gray icon icon_cancel lbCancel" href="javascript:__doPostBack('ctl00$BodyPlaceHolder$lbCancel','')"><i aria-hidden="true" role="presentation" tabindex="-1"></i><strong>Cancel</strong></a>
</div>

    <div class="right">
      <a id="ctl00_BodyPlaceHolder_lbSearch" class="button button_ui button_yellow icon icon_search lbSearch" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$BodyPlaceHolder$lbSearch&quot;, &quot;&quot;, true, &quot;Search&quot;, &quot;&quot;, false, true))"><i aria-hidden="true" role="presentation" tabindex="-1"></i><strong>Search</strong></a>
      </div>
</div>

这些是尝试过的代码,但没有一个可以“搜索”来过滤交易:

driver.find_element_by_css_selector("a.ctl00_BodyPlaceHolder_lbSearch.button.button_ui.button_yellow.icon.icon_search.lbSearch").click()
driver.find_element_by_id("ctl00_BodyPlaceHolder_lbSearch").click()
driver.find_element_by_css_selector("div.right a#ctl00_BodyPlaceHolder_lbSearch.button.button_ui.button_yellow.icon.icon_search.lbSearch").click()
driver.find_element_by_xpath("//a[@id ='ctl00_BodyPlaceHolder_lbSearch']").click()
driver.find_element_by_xpath("//i[@role ='presentation']").click()
driver.find_element_by_xpath("//i[@aria-hidden ='true']").click()
driver.find_element_by_xpath("//i[@role ='presentation' and @tabindex = '1']").click()
driver.find_element_by_id("ctl00_BodyPlaceHolder_lbSearch").submit()
driver.find_element_by_xpath("//a[@id ='ctl00_BodyPlaceHolder_lbSearch']").submit()
driver.find_element_by_link_text("Search").submit()
driver.find_element_by_link_text("Search").click()
driver.execute_script('WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$BodyPlaceHolder$lbSearch", "", true, "Search", "", false, true))')
driver.find_element_by_xpath("//a[@id = 'ctl00_BodyPlaceHolder_lbSearch']/i[@role ='presentation']").click()
driver.find_element_by_xpath("//a[@class = 'button button_ui button_yellow icon icon_search lbSearch']/i[@role ='presentation']").click()
driver.find_elements_by_xpath("//i[@role ='presentation'][5]").click()
search_date = driver.find_elements_by_xpath("//i[5]")
search_date.click()
driver.find_element_by_xpath("//a[i/@role ='presentation']").click()
driver.find_element_by_xpath("//a/@id='ctl00_BodyPlaceHolder_lbSearch'[i/@role ='presentation']").click()
driver.find_element_by_xpath(".//div[@class='ButtonPanel']/div[@class='right']/a[@id='ctl00_BodyPlaceHolder_lbSearch']/i[@role='presentation']")
driver.find_element_by_xpath(".//div[@class='ButtonPanel']/div[@class='right']/a[@id='ctl00_BodyPlaceHolder_lbSearch']").click()
driver.find_element_by_xpath(".//div[@class='ButtonPanel']/div[@class='right']/a[@class='button button_ui button_yellow icon icon_search lbSearch']").click()
river.find_element_by_link_text("Search").click()

形式

html代码

标签: pythonselenium-chromedriver

解决方案


推荐阅读