我一直在嘗試找出任何方法來單擊Download base consolidada此網頁上可見的按鈕。該按鈕似乎在 iframe 內。似乎我已經能夠切換到iframe該按鈕并使用我在以下腳本中定義的一些 xpath 找到該按鈕的元素。但是,當單擊該按鈕時,腳本會引發一些錯誤。
我正在嘗試:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
link = "https://www.anbima.com.br/pt_br/autorregular/matriz-de-probabilidade-de-resgates.htm"
with webdriver.Chrome() as driver:
wait = WebDriverWait(driver,20)
driver.get(link)
wait.until(EC.frame_to_be_available_and_switch_to_it(wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "iframe")))))
wait.until(EC.element_to_be_clickable((By.XPATH,"//span[@class='textRun'][.='Download base consolidada']"))).click()
這是我得到的錯誤:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <span class="textRun" style="font-size: 14pt; font-weight: bold; color: rgb(0, 135, 202);">...</span> is not clickable at point (345, 90). Other element would receive the click: <rect x="4.02685069008783" y="1.961104140526976" width="244.63136762860728" height="42.18820577164366" rx="8" ry="8" style="vector-effect: non-scaling-stroke; stroke-width: 3px; stroke: rgb(0, 149, 217); stroke-opacity: 1; fill: rgb(243, 242, 241); fill-opacity: 0;"></rect>
(Session info: chrome=98.0.4758.102)
Stacktrace:
Backtrace:
Ordinal0 [0x00307AC3 2587331]
Ordinal0 [0x0029ADD1 2141649]
Ordinal0 [0x00193BB8 1063864]
Ordinal0 [0x001C65FF 1271295]
and so on--------------------
如何使用硒單擊上述按鈕?
uj5u.com熱心網友回復:
driver.get('https://www.anbima.com.br/pt_br/autorregular/matriz-de-probabilidade-de-resgates.htm')
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(WebDriverWait(driver, 60).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "iframe")))))
WebDriverWait(driver, 40).until(EC.visibility_of_element_located((By.XPATH, "(//*[@data-automation-type='visualContainerHost']//div[contains(@aria-label, 'Web URL')])[1]"))).click()
time.sleep(5)
driver.quit()
這給了我輸出:
Process finished with exit code 0這意味著沒有錯誤并且代碼成功運行。
這是通過代碼下載的檔案的快照: Excel檔案快照
uj5u.com熱心網友回復:
這是因為您嘗試單擊的元素不是接受實際單擊的元素,而是 rect 元素。嘗試用包含 rect 元素的 div 替換 span 的 Xpath,它應該可以作業。
wait.until(EC.element_to_be_clickable((By.XPATH,"//div[@aria-describedby='visualsEnterHint-e780d1b86be1529ccdf0']/div[3]/div/visual-modern/div/div"))).click()
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/424255.html
標籤:Python python-3.x 硒 硒网络驱动程序 网页抓取
