python - 如何使用selenium查找是否选择了ng-grid行

标签 python selenium selenium-webdriver

我试图从 div 结构中找到 ng-grid 单元格,如下面的屏幕截图所示,使用以下 xpath 并单击它。

"//div[@class='ui-grid-cell-contents ng-binding ng-scope' and contains(text(), 'Stefan')]"

这个 xpath 正在工作,但是如何在单击该行之前确定该行是否已被选中。

enter image description here

有一个父类名表示该行是否被选中,我使用了以下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/

相关文章:

java流比较列表与局部变量

java - 在 Selenium 中每个元素使用多个定位器的优缺点?

python - 如何在 Django 中使用一个提交按钮提交多个表单?

python - Celery、RabbitMQ 消息不断发送

python - 在同一个conda环境中安装Python3.9和PyPy3.7

java - 捕获多个 webdriver 异常时如何 OR

java - selenium webdriver 的意外行为

python - 获取包含特定文本的 td,然后找到其 parent 和 sibling

python-3.x - 一个进程请求访问一个对象,但没有被授予这些访问权限在 windows 10 上使用 Selenuim 和 Chrome 驱动程序

python - 将 Python 列表传递给嵌入式 Rust 函数