问题描述
用于Python/Django的API中的硒具有功能driver.find_element/elements_by_class_name(),但未编写是否可以将其用于多个类我需要选择具有bj,bd,bi等几个类的元素如果可能的话,怎么办?
Selenium in the API for Python / Django has the function driver.find_element/elements_by_class_name (), but it is not written whether it can be used for several classesI need choose element with several classes like bj,bd,biIf possible, how?
推荐答案
答案为否,您不能将driver.find_element_by_class_name ()
或driver.find_elements_by_class_name ()
与多个类名一起使用.它仅接受单个类名.
The answer is No, You can't use driver.find_element_by_class_name ()
or driver.find_elements_by_class_name ()
with multiple class names. It accepts only single class name.
但是,您可以使用find_elements_by_xpath
或find_element_by_css_selector
方法来实现查找具有多个类名的元素.
However, you can use find_elements_by_xpath
or find_element_by_css_selector
method to achieve finding element with multiple class names.
例如下面的代码将使用两个不同的类名在Google网站上查找元素.
for example below code will find element on google website using two different class names.
url= "http://google.com"
driver = webdriver.Chrome()
driver.get(url)
driver.find_elements_by_xpath("//*[@class='sfibbbc' or @class='jsb']")
# Following line will result in error
driver.find_elements_by_class_name("sfibbbc jsb")
这篇关于多个类的find_element_by_class_name的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!