Le problème que je suis confronté réside dans l'itération de ces boucles, une fois que le premier fichier est téléchargé à partir du site web Je reçois une erreur:Python Sélénium: Stale Élément de référence Exception Erreur
« selenium.common.exceptions. StaleElementReferenceException: Message: La référence d'élément de stale: soit l'élément n'est plus attaché au DOM ou la page a été rafraîchie "
Le" 97081 data-extension xml "est le 2ème fichier téléchargeable de l'itération. J'ai joint le code, toutes les suggestions pour rectifier cela seront très appréciées.
import os
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList", 2)
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.dir", "F:\Projects\Poli_Map\DatG_Py_Dat")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/xml")
driver = webdriver.Firefox(firefox_profile=fp)
driver.get('https://data.gov.in/catalog/variety-wise-daily-market-prices-data-cauliflower')
wait = WebDriverWait(driver, 10)
allelements = driver.find_elements_by_xpath("//a[text()='xml']")
for element in allelements:
element.click()
class FormPage(object):
def fill_form(self, data):
driver.execute_script("document.getElementById('edit-download-reasons-non-commercial').click()")
driver.execute_script("document.getElementById('edit-reasons-d-rd').click()")
driver.find_element_by_xpath('//input[@name = "name_d"]').send_keys(data['name_d'])
driver.find_element_by_xpath('//input[@name = "mail_d"]').send_keys(data['mail_d'])
return self
def submit(self):
driver.execute_script("document.getElementById('edit-submit').click()")
data = {
'name_d': 'xyz',
'mail_d': '[email protected]',
}
time.sleep(5)
FormPage().fill_form(data).submit()
time.sleep(5)
window_before = driver.window_handles[0]
driver.switch_to_window(window_before)
driver.back()
Merci Andersson, pour la réponse en temps opportun. Cela fonctionne bien. – Cashi