Chrome 无法在Selenium Python中单击复选框

ax6ht2ek  于 2023-10-14  发布在  Go
关注(0)|答案(1)|浏览(124)

我正在尝试从下一个网页下载文件:
https://www.superfinanciera.gov.co/SIMEV2/rnve/informesfinancierosniif/110/000001/0
却翻不到最后一页
我的代码:

options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--no-sandbox")
driver = webdriver.Chrome(options=options)
driver.get('https://www.superfinanciera.gov.co/SIMEV2/rnve')
busqueda_texto = driver.find_element(By.XPATH, '//*[@id="searchBarRNVE"]/div/input')
busqueda_texto.send_keys(seleccion)
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="searchBarRNVE"]/div/a[2]/a/span'))).click()
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="cardRNVE"]'))).click()
time.sleep(3)
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="dropdownMenuButton"]'))).click()
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="dropdownSubmenuButton"]/li[1]/a[11]'))).click()
time.sleep(3)

## AÑO
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="anioConsulta"]'))).click()
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '/html/body/app-root/app-layout-reportes-rnve/div/app-informes-financieros-niif/feature-toggle-provider/div/div/div[1]/div/div[1]/div/div/div/div[2]'))).click()

## TIPO DE REPORTE
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '/html/body/app-root/app-layout-reportes-rnve/div/app-informes-financieros-niif/feature-toggle-provider/div/div/div/div/div[2]/div/div'))).click()
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '/html/body/app-root/app-layout-reportes-rnve/div/app-informes-financieros-niif/feature-toggle-provider/div/div/div/div/div[2]/div/div/div/option[2]'))).click()

我得到的错误是:

---------------------------------------------------------------------------
TimeoutException                          Traceback (most recent call last)
<ipython-input-99-c1f3ee3cdf7e> in <cell line: 24>()
     22 WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '/html/body/app-root/app-layout-reportes-rnve/div/app-informes-financieros-niif/feature-toggle-provider/div/div/div/div/div[2]/div/div'))).click()
     23 WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '/html/body/app-root/app-layout-reportes-rnve/div/app-informes-financieros-niif/feature-toggle-provider/div/div/div/div/div[2]/div/div'))).click()
---> 24 WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '/html/body/app-root/app-layout-reportes-rnve/div/app-informes-financieros-niif/feature-toggle-provider/div/div/div/div/div[2]/div/div/option[2]'))).click()
     25 
     26 

/usr/local/lib/python3.10/dist-packages/selenium/webdriver/support/wait.py in until(self, method, message)
     93             if time.monotonic() > end_time:
     94                 break
---> 95         raise TimeoutException(message, screen, stacktrace)
     96 
     97     def until_not(self, method, message: str = ""):

TimeoutException: Message: 
Stacktrace:
#0 0x586cdb24e6b3 <unknown>
#1 0x586cdaf241e7 <unknown>
#2 0x586cdaf6b566 <unknown>
#3 0x586cdaf6b651 <unknown>
#4 0x586cdafa8a74 <unknown>
#5 0x586cdaf8d0ed <unknown>
#6 0x586cdafa6322 <unknown>
#7 0x586cdaf8ce93 <unknown>
#8 0x586cdaf5f934 <unknown>
#9 0x586cdaf6071e <unknown>
#10 0x586cdb213cb8 <unknown>
#11 0x586cdb217bf0 <unknown>
#12 0x586cdb22219c <unknown>
#13 0x586cdb218808 <unknown>
#14 0x586cdb1e527f <unknown>
#15 0x586cdb23ce88 <unknown>
#16 0x586cdb23d059 <unknown>
#17 0x586cdb24d843 <unknown>
#18 0x7f494be08b43 <unknown>

在名为“Tipo de Report”的对话框中,我无法单击第二个选项。我尝试了XPATH和CSS_SELECTOR,但总是得到同样的错误。
任何帮助将非常感谢。
注意:我放在代码中的XPATH是当我点击“复制xpath”按钮时Chrome给予给我的。

vx6bjr1n

vx6bjr1n1#

我已经解决了任何人面临同样的问题。
解决方案是使用JSExtractor:

options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--no-sandbox")
driver = webdriver.Chrome(options=options)
driver.get('https://www.superfinanciera.gov.co/SIMEV2/rnve')
busqueda_texto = driver.find_element(By.XPATH, '//*[@id="searchBarRNVE"]/div/input')
busqueda_texto.send_keys(seleccion)
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="searchBarRNVE"]/div/a[2]/a/span'))).click()
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="cardRNVE"]'))).click()
time.sleep(3)
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="dropdownMenuButton"]'))).click()
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="dropdownSubmenuButton"]/li[1]/a[11]'))).click()
time.sleep(3)

## AÑO
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="anioConsulta"]'))).click()
WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '/html/body/app-root/app-layout-reportes-rnve/div/app-informes-financieros-niif/feature-toggle-provider/div/div/div[1]/div/div[1]/div/div/div/div[2]'))).click()

## TIPO DE REPORTE
dropdown = driver.find_element(By.XPATH, '/html/body/app-root/app-layout-reportes-rnve/div/app-informes-financieros-niif/feature-toggle-provider/div/div/div/div/div[2]/div/div')
driver.execute_script('arguments[0].scrollIntoView();', dropdown)
dropdown.click()
driver.execute_script("arguments[0].click();", driver.find_element(By.XPATH, '/html/body/app-root/app-layout-reportes-rnve/div/app-informes-financieros-niif/feature-toggle-provider/div/div/div/div/div[2]/div/div/div/option[2]'))

相关问题