如何使用Python / XPATH获取类属性的内容?

时间:2019-07-14 15:41:12

标签: python-3.x xpath

是否可以获取类属性的内容,以及如何实现?

3 个答案:

答案 0 :(得分:0)

该类的名称为self。

    tform = driver.find_elements_by_xpath("//table[@id = 'table-type-1']/tbody/tr/td[@class ='form col_form']/div/a[@class]") 

Print(tform.text)返回正确的命中数,但字符串为空

答案 1 :(得分:0)

尝试一下。

linkClass = driver.find_element_by_xpath("//table[@id = 'table-type-1']/tbody/tr/td[@class ='form col_form']/div/a").get_attribute('class')
print(linkClass)

答案 2 :(得分:0)

    linkClass = driver.find_elements_by_xpath("//table[@id = 'table-type-1']/tbody/tr/td[@class ='form col_form']/div/a[@href]").__getattribute__('class')

AttributeError:“列表”对象没有属性“类”