Home > OS >  Download files opened in an inner window with Selenium
Download files opened in an inner window with Selenium

Time:07-03

I want to download files on https://aplicaciones007.jne.gob.pe/srop_publico/Consulta/PadronAfiliado# The problem I am facing is when I click on some of the entries, for instance the first one 'ACCION POPULAR', a new inner window pops up which I cannot interact with Selenium. Here are the lines to click on one of the 6 files opened after clicking on 'ACCION POPULAR'. However, it doesn't click on the files and I basically tried all possible XPATHS for the files.

for i in range(1,7):
                file_path = '//*[@id="MiVentanaContenido"]/div[2]/table/tbody/tr[1]/td'
                file = driver.find_element(By.XPATH, file_path)
                print(file.text)
                file.click()
               

CodePudding user response:

The reason it is not clicking on the 6 links after clicking on ACCION POPULAR is because we are specifying to click on the table data row //*[@id="MiVentanaContenido"]/div[2]/table/tbody/tr[1]/td instead of the anchor link present in the row i.e //*[@id="MiVentanaContenido"]/div[2]/table/tbody/tr[1]/td/a

Your solution would look like

driver = webdriver.Chrome()  
driver.get('https://aplicaciones007.jne.gob.pe/srop_publico/Consulta/PadronAfiliado#') 
driver.maximize_window()
wait =WebDriverWait(driver, 5) 
wait.until(
EC.presence_of_element_located((By.XPATH, "//div[text()='ACCION POPULAR']"))
).click()
wait.until(EC.presence_of_element_located((By.XPATH, "//table[@class='table table-striped table-bordered']/descendant::a")))
list = driver.find_elements(By.XPATH, "//table[@class='table table-striped table-bordered']/descendant::a") 
for file in list:
 print(file.text)
 file.click()
  • Related