报错信息:UserWarning: find_elements_by_class_name is deprecated. Please use find_elements(by=By.CLASS_NAME, value=name) instead
warnings.warn("find_elements_by_class_name is deprecated. Please use find_elements(by=By.CLASS_NAME, value=name) instead")
查询后发现该方法已经被弃用,需要用find_element()方法替代,使用方法如下:
driver.find_element(By.ID,"J_goodsList")
#想查的是id就写By.ID,是class就写CLASS_NAME
#感觉变动不是很大,也还挺方便
find_element()方法的源码如下:
def find_element(self, by=By.ID, value=None):
"""
Find an element given a By strategy and locator.
:Usage:
::
element = element.find_element(By.ID, 'foo')
:rtype: WebElement
"""
if by == By.ID:
by = By.CSS_SELECTOR
value = '[id="%s"]' % value
elif by == By.TAG_NAME:
by = By.CSS_SELECTOR
elif by == By.CLASS_NAME:
by = By.CSS_SELECTOR
value = ".%s" % value
elif by == By.NAME:
by = By.CSS_SELECTOR
value = '[name="%s"]' % value
return self._execute(Command.FIND_CHILD_ELEMENT,
{"using": by, "value": value})['value']
最后记得导入这个包:
from selenium.webdriver.common.by import By