请求Selenium*通过类名称查找元素

请求Selenium*通过类名称查找元素,selenium,selenium-webdriver,Selenium,Selenium Webdriver,我尝试从“有用”和“无用”按钮获取文本,但未能成功: 例如:我想得到“6013”表示有用的分数,“320”表示无用的分数: 我的代码是: product_helpful.append(container.find_element_by_class_name('css-0').text) product_not_helpful.append(container.find_element_by_class_name('css-0').text) 您可以查看图片以供参考: 使用title属性

我尝试从“有用”和“无用”按钮获取文本,但未能成功:

例如:我想得到“6013”表示有用的分数,“320”表示无用的分数:

我的代码是:

product_helpful.append(container.find_element_by_class_name('css-0').text)    
product_not_helpful.append(container.find_element_by_class_name('css-0').text)
您可以查看图片以供参考:


使用title属性以代码中有用与无用的部分为目标

product_helpful.append(container.find_element_by_css_selector('[title="Helpful"] span').text)    
product_not_helpful.append(container.find_element_by_css_selector('[title="Unhelpful"] span').text)

请注意,为此,您必须使用WebElement中的
find\u element\u by\u css\u selector
方法。

类为“css-0”的元素不止一个。您希望selenium如何知道引用哪一个?…使用title属性将有用与无用作为目标。。真棒的解释,当然!我就这么做了