单击按钮(python),机械化和硒都有问题
Click button (python), having problems with both mechanize and selenium
我试图点击 "Coevolution Scores (TXT)" 按钮,它在点击 "Export..." 按钮后弹出,但是,使用 python 脚本 here,我无法使用不同的选择类型,使用 mechanize 或 selenium 来完成。
还有其他方法吗,或者你能找出我做错了什么吗?
我使用了这个代码:
url="http://polyview.cchmc.org/cgi-bin/coevolve.cgi?JOB=c8a266e0d7ba7cc"
driver = webdriver.Chrome(executable_path="C:/ProgramFiles/Google/Chrome/Application/chromedriver.exe")
driver.get(url)
time.sleep(15)
driver.find_element(by=By.XPATH, value="//button[@title='Export...']").click()
也尝试过 link_text 并通过放置 find_element_by_link_text
,而不是将参数放在里面。下面是我尝试点击的按钮。
<form id="downloadMat" target="formTarget" method="POST" action="coeviz_data.pl">
<input name="x" class="idData" type="hidden" value="683436.chi">
<input name="dl" class="dlData" type="hidden" value="683436.chi.wph">
<input name="w" class="weighted" type="hidden" value="wph">
<input name="res" type="hidden" value="scores.txt">
<button onclick="submit()">Coevolution Scores (TXT)</button>
</form>
您尝试 select 的代码在 <iframe>
元素内。这意味着您必须先切换框架,然后再 selecting 里面的任何东西。这将起作用:
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
url="http://polyview.cchmc.org/cgi-bin/coevolve.cgi?JOB=c8a266e0d7ba7cc"
driver = webdriver.Chrome(executable_path="C:/ProgramFiles/Google/Chrome/Application/chromedriver.exe")
driver.get(url)
time.sleep(15)
driver.switch_to_frame('ifCoeViz')
driver.find_element(by=By.XPATH, value="//button[@title='Export...']").click()
我试图点击 "Coevolution Scores (TXT)" 按钮,它在点击 "Export..." 按钮后弹出,但是,使用 python 脚本 here,我无法使用不同的选择类型,使用 mechanize 或 selenium 来完成。
还有其他方法吗,或者你能找出我做错了什么吗?
我使用了这个代码:
url="http://polyview.cchmc.org/cgi-bin/coevolve.cgi?JOB=c8a266e0d7ba7cc"
driver = webdriver.Chrome(executable_path="C:/ProgramFiles/Google/Chrome/Application/chromedriver.exe")
driver.get(url)
time.sleep(15)
driver.find_element(by=By.XPATH, value="//button[@title='Export...']").click()
也尝试过 link_text 并通过放置 find_element_by_link_text
,而不是将参数放在里面。下面是我尝试点击的按钮。
<form id="downloadMat" target="formTarget" method="POST" action="coeviz_data.pl">
<input name="x" class="idData" type="hidden" value="683436.chi">
<input name="dl" class="dlData" type="hidden" value="683436.chi.wph">
<input name="w" class="weighted" type="hidden" value="wph">
<input name="res" type="hidden" value="scores.txt">
<button onclick="submit()">Coevolution Scores (TXT)</button>
</form>
您尝试 select 的代码在 <iframe>
元素内。这意味着您必须先切换框架,然后再 selecting 里面的任何东西。这将起作用:
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
url="http://polyview.cchmc.org/cgi-bin/coevolve.cgi?JOB=c8a266e0d7ba7cc"
driver = webdriver.Chrome(executable_path="C:/ProgramFiles/Google/Chrome/Application/chromedriver.exe")
driver.get(url)
time.sleep(15)
driver.switch_to_frame('ifCoeViz')
driver.find_element(by=By.XPATH, value="//button[@title='Export...']").click()