通过selenium用于span类的driver.find_element_by_xpath选择元素

时间:2016-04-12 06:45:29

标签: python-2.7 selenium xpath

我正在尝试抓取数据并使用xpath从页面中单击ot。例如,我想要的内容采用以下格式

<div class="x-grid-cell-inner x-grid-cell-inner-treecolumn" style="text-align:left;" unselectable="on">
<img class=" x-tree-elbow-img x-tree-elbow-empty" role="presentation" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==">
<img class=" x-tree-elbow-img x-tree-elbow-line" role="presentation" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==">
<img class=" x-tree-elbow-img x-tree-elbow" role="presentation" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==">
<img class=" x-tree-icon x-tree-icon-leaf " role="presentation" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==">
<span class="x-tree-node-text ">Chassis</span>

我使用了函数// span [contains(@class,'x-tree-node-text')]。机箱但它没有返回任何内容。

任何帮助?

2 个答案:

答案 0 :(得分:0)

尝试以下XPath: -

//span[@class='x-tree-node-text ']

或更具体

//span[@class='x-tree-node-text ' and contains(.,'Chassis')]

希望它会对你有所帮助:)。

答案 1 :(得分:0)

您是否也想找到“Chassis”字样?很难看出你没有把你的XPath放在反引号中。

但如果是这样,那么你的XPath就错了。你必须使用:

//span[contains(@class, 'x-tree-node-text')][.='Chassis']