这应该工作:
.//button[.='OK' and not(ancestor::div[contains(@style,'display:none')])and not(ancestor::div[contains(@style,'display: none')])]
编辑:
下面是更简单,更有效的表达式:
//div[not(contains(@style,'display:none'))]//button[.='OK']
无法正常工作,因为每个按钮在其祖先中至少有一个div可见。

这应该工作:
.//button[.='OK' and not(ancestor::div[contains(@style,'display:none')])and not(ancestor::div[contains(@style,'display: none')])]
编辑:
下面是更简单,更有效的表达式:
//div[not(contains(@style,'display:none'))]//button[.='OK']
无法正常工作,因为每个按钮在其祖先中至少有一个div可见。