首页 > 解决方案 > 问题“ driver.find_element_by_xpath("//div[@class='example']"

问题描述

这几天我一直在遇到这个问题。我使用 Pycharm 和 Python:

UserWarning: find_element_by_* commands are deprecated. Please use find_element() instead
warnings.warn("find_element_by_* commands are deprecated. Please use find_element() instead")

问候

标签: pythonselenium-chromedriver

解决方案


尝试以下...

首先,导入By如下:from selenium.webdriver.common.by import By

然后,如果您尝试通过 xpath 查找元素,例如,请替换:

find_elements_by_xpath("[***whatever the xpath is***]")

和:

driver.find_element(By.XPATH, "[***whatever the xpath is***]")

有关调用元素的各种方法的示例,请参阅Selenium with Python 参考网站


推荐阅读