Ich versuche, ein Web-Datei-Download-Programm mit Selenium in Python zu automatisieren. Aber ich habe einige Schwierigkeiten beim Anklicken einer bestimmten Taste mit Selenium: Das Programm führt erfolgreich zu dieser URL 'https://www.sec.gov/Archives/edgar/data/1467373/000119312510235847/0001193125-10-235847-index.htm', aber es kann nicht auf die Schaltfläche des ersten Dokuments (d10k.htm) klicken. Die Schaltfläche ist im folgenden Code als 'formbuttonElement' definiert und ich habe sie mit Xpath verfolgt. Außerdem habe ich sowohl click() als auch .send_keys (Keys.SPACE) Methoden verwendet, aber sie haben nicht funktioniert.Python Selenium click() funktioniert nicht
Kann sich jemand dieses Problem ansehen?
Vielen Dank!
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import unittest
import os
class LoginTest(unittest.TestCase):
def setUp(self):
fp=webdriver.FirefoxProfile(r"C:\Users\sxc\AppData\Roaming\Mozilla\Firefox\Profiles\x5i7u4m7.profileToolsQA")
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir", "D:\doc1")
fp.set_preference("pdfjs.disabled", True)
fp.set_preference("plugin.disable_full_page_plugin_for_types", "application/pdf")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/pdf")
self.driver=webdriver.Firefox(firefox_profile=fp)
self.driver.get("https://www.sec.gov/edgar/searchedgar/companysearch.html")
def test_Login(self):
driver=self.driver
cikID="cik"
searchButtonID="cik_find"
typeID="//*[@id='type']"
priorID="prior_to"
cik="00001467373"
Type="10-K"
prior="201"
search2button="//*[@id='contentDiv']/div[2]/form/table/tbody/tr/td[6]/input[1]"
documentsbuttonid="documentsbutton"
formbuttonxpath="(//a[contains(@href,'/Archives/edgar/data/')])[1]"
cikElement=WebDriverWait(driver,30).until(lambda driver:driver.find_element_by_id(cikID))
cikElement.clear()
cikElement.send_keys(cik)
searchButtonElement=WebDriverWait(driver,20).until(lambda driver:driver.find_element_by_id(searchButtonID))
searchButtonElement.click()
typeElement=WebDriverWait(driver,30).until(lambda driver:driver.find_element_by_xpath(typeID))
typeElement.clear()
typeElement.send_keys(Type)
priorElement=WebDriverWait(driver,30).until(lambda driver:driver.find_element_by_id(priorID))
priorElement.clear()
priorElement.send_keys(prior)
search2Element=WebDriverWait(driver,30).until(lambda driver:driver.find_element_by_xpath(search2button))
search2Element.send_keys(Keys.SPACE)
time.sleep(1)
documentsButtonElement=WebDriverWait(driver,20).until(lambda driver:driver.find_element_by_id(documentsbuttonid))
documentsButtonElement.click()
formElement=WebDriverWait(driver,30).until(lambda driver:driver.find_element_by_xpath(formbuttonxpath))
formElement.send_keys(Keys.SPACE)
def terdown(self):
self.driver.quit()
if __name__=='__main__':
unittest.main()
Great! Vielen Dank!! – SXC88
hi Ich habe eine neue Frage über Python, aber auf eine allgemeinere Art ... vielleicht willst du es dir anschauen! http://stackoverflow.com/questions/40744250/python-setting-limit-for-running-time-with-while-loop – SXC88