我试图从 div 结构中找到 ng-grid 单元格,如下面的屏幕截图所示,使用以下 xpath 并单击它。
"//div[@class='ui-grid-cell-contents ng-binding ng-scope' and contains(text(), 'Stefan')]"
这个 xpath 正在工作,但是如何在单击该行之前确定该行是否已被选中。
有一个父类名表示该行是否被选中,我使用了以下Xpath的使用父div,但它似乎不起作用。
//div[@class='ui-grid-row ng-scope' and contains(text(), 'Stefan')]
//div[@class='ui-grid-row ng-scope ui-grid-row-selected' and contains(text(), 'Stefan')]
还有其他方法可以实现这一目标吗?
最佳答案
要检查ng-grid单元格是否被选中,您可以使用以下代码块:
divClasses = driver.find_element_by_xpath("//div[@class='ui-grid-cell-contents ng-binding ng-scope' and contains(text(), 'Stefan')]//ancestor::div[@class='ui-grid-row ng-scope']").get_attribute("class")
if "ui-grid-row-selected" in divClasses :
print("Row is selected")
else :
print("Row is not selected")
关于python - 如何使用selenium查找是否选择了ng-grid行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49042698/