如何將 EC.presence_of_element_ located 與類別屬性一起使用
當將 selenium 的 EC.presence_of🎜>
當將 selenium 的 EC.presence_of_一起使用時,您可以指定要透過以下方式尋找的元素它的類別屬性而不是它的 ID。具體做法如下:原始程式碼:element = WebDriverWait(driver,100).until(EC.presence_of_element_located((By.ID, "tabla_evolucion")))嘗試透過 ID 找出元素。若要按類別尋找元素,請將「By.ID」變更為「By.CLASS」並提供類別名稱:
element = WebDriverWait(driver,100).until(EC.presence_of_element_located((By.CLASS, "ng-binding ng-scope")))
注意:
避免使用 Presence_of_element_ located 進行互動操作。相反,更喜歡visibility_of_element_ located 或element_to_be_clickable。另外:
# CSS_SELECTOR element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located( (By.CSS_SELECTOR, ".ng-binding.ng-scope#tabla_evolucion"))) # XPATH element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located( (By.XPATH, "//*[@class='ng-binding ng-scope' and @id='tabla_evolucion']")))
以上是如何使用 Selenium 的 EC.presence_of_element_ located 依類別屬性定位元素?的詳細內容。更多資訊請關注PHP中文網其他相關文章!