簡體   English   中英

無法找到硒中的元素:{“方法”:“ css選擇器”,“選擇器”:“ [id =” identifierId”]”}

[英]Unable to locate element: {“method”:“css selector”,“selector”:“[id=”identifierId“]”} in selenium

我想通過電子郵件自動下載到本地並發送報告(儀表板數據工作室),但是當我在數據工作室中運行代碼時,chrome驅動程序會打開,並顯示“此時無法查看報告或無法訪問報告”通知我該怎么辦? 這是我的代碼:

# login to datastudio & refresh the newest data
self.chrome_driver.get(self.url)  
self.chrome_driver.find_element_by_id("identifierId").send_keys(self.email + u'\ue007')
self.quick_wait.until(EC.element_to_be_clickable((By.NAME, "password"))).send_keys(self.password+u'\ue007')
self.quick_wait.until(EC.element_to_be_clickable((By.XPATH, self.report_refresh))).click() # refresh report data
time.sleep(15)
# download file to local path
try:
    ActionChains(self.chrome_driver).context_click(self.chrome_driver.find_element_by_xpath(self.product_export)).perform()
    self.quick_wait.until(EC.element_to_be_clickable((By.XPATH, self.product_download))).click()
    time.sleep(20)
    self.quick_wait.until(EC.element_to_be_clickable((By.ID, self.report_download))).click()
    self.chrome_driver.find_element_by_css_selector(self.report_to_pdf).click()
    time.sleep(20)
except AssertionError as error:
    print(error)
    self.chrome_driver.quit()

我收到錯誤消息,例如:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="identifierId"]"}

在此處輸入圖片說明

在此處輸入圖片說明

在此處輸入圖片說明

在此處輸入圖片說明

頁面加載可能是一個問題。嘗試添加隱式或顯式等待。

1.應用所需的等待(隱式或顯式等待)

隱式等待

driver.implicitly_wait(15)

顯式等待:

wait = WebDriverWait(driver, 10)
wait.until(ec.visibility_of_element_located((By.XPATH, "//*[contains(@class,'result-list-entry')]")))

例:

self.chrome_driver.implicitly_wait(15)
self.chrome_driver.get(self.url)
self.quick_wait.until(EC.element_to_be_clickable((By.ID, "identifierId")))
self.chrome_driver.find_element_by_id("identifierId").send_keys(self.email + u'\ue007')
self.quick_wait.until(EC.element_to_be_clickable((By.NAME, "password"))).send_keys(self.password+u'\ue007')

2.檢查元素是否是iframe元素的子元素。 如果是這樣,請切換至iframe並嘗試點擊

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 收到消息:沒有這樣的元素:無法找到元素:{"method":"css selector","selector":"[id="None"]"} Python 使用 selenium 時 使用 Selenium Python 選擇下拉菜單 - 無法定位元素:{“method”:“css selector”,“selector”:"[id= selenium.common.exceptions.NoSuchElementException:消息:沒有這樣的元素:無法找到元素:{“方法”:“css選擇器”,“選擇器”:“.ui流感~”} 消息:沒有這樣的元素:無法找到元素:{“method”:“css selector”,“selector”:“[id=”loginUsername“]”} Selenium NoSuchElementException-無法找到元素:{“方法”:“ css選擇器”,“選擇器”:“ [[名稱=”電子郵件地址”]”} 沒有這樣的元素:無法定位元素:{“method”:“css selector”,“selector”:“[id=”guided-tour-tag-credentials-new“]”} NoSuchElementException:消息:沒有這樣的元素:無法找到元素:{"method":"css selector","selector":"[id="events_table"]"} 無法定位元素:{“method”:“css selector”,“selector”:“.Mr508”} Python: Selenium 沒有這樣的元素: 無法定位元素: {“method”:“xpath”,“selector”:“//button[@data-id=1]”} selenium 無法使用方法定位元素:無法通過 id、css_selector、xpath、鏈接文本找到元素
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM