背景: 用WebDriverWait時,一開始用的是presence_of_element_located,我對它的想法就是他就是用來等待元素出現。結果屢屢出問題。元素默認是隱藏的,致使等待過早的就結束了。app
解決:去StackOverFlow查了一下,發現我應該用visibility_of_element_located。post
Well, I would guess that presenceOfElementLocated will be slighty faster because it's just check elements presence on the page while the visibilityOfElementLocated has to check the presenceand whether is element visible. But I think it really doesn't matter from the performance perspective (what's the point if you save 0.001 second during this checking?), you better choose appropriate method depending on your use case. use presenceOfElementLocated when you don't care whether if element visible or not, you just need to know if it's on the page use visibilityOfElementLocated when you need to find element which should be also visible Look at the documentation for more info.
我猜 presence_of_element_located 確定會稍微快一點,由於它僅僅檢查了頁面是否存在該元素,而visibility_of_element_located還必須檢查元素是否存在以及元素是否可見。性能
可是我認爲從性能角度考慮,確實沒啥影響。最好根據使用狀況來選擇正確的方法。this