使用 Python 的 Selenium 中,隱式等待和顯式等待有什麼區別?


隱式等待和顯式等待之間的區別如下所示:


隱式等待顯式等待
1要求驅動程式等待特定時間,以便元素在頁面 DOM 中可用。
要求驅動程式等待,直到滿足某個條件。
2它是全域性等待,適用於網頁上的所有元素。
它不是全域性等待,適用於特定場景。
3它不需要滿足任何條件。
它需要滿足特定條件。一些預期的條件包括:
  • title_contains
  • visibility_of_element_located
  • presence_of_element_located
  • title_is
  • visibility_of
  • element_selection_state_to_be
  • presence_of_all_elements_located
  • element_located_to_be_selected
  • alert_is_present
  • element_located_selection_state_to_b e
  • staleness_of
  • element_to_be_clickable
  • invisibility_of_element_located
  • frame_to_be_available_and_switch_to _it
  • text_to_be_present_in_element_value
  • text_to_be_present_in_element
  • element_to_be_selected
4語法
driver.implicitly_wait(2)
語法
w = WebDriverWait(driver, 7)
w.until(expected_conditions.presence_of_ele
ment_located((By.ID, "Tutorialspoint")))
5它簡單易於實現。
與隱式等待相比,它的實現更復雜。
6它會影響執行速度,因為每個步驟都會等待此等待,直到找到它正在尋找的元素。
它不會影響執行速度,因為它適用於頁面的特定元素。
7它不會捕獲應用程式中的效能問題。
它可以捕獲應用程式中的效能問題。

更新於: 2020-07-28

11K+ 瀏覽量

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告