如何将 EC.presence_of_element_ located 与类属性一起使用
当将 selenium 的 EC.presence_of_element_ located 方法与 WebDriverWait 一起使用时,您可以指定要通过以下方式查找的元素它的类属性而不是它的 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中文网其他相关文章!