同一DIV中存在两个按钮的XPath逻辑AND
我有一个XPath表达式,它使用以下内容正确验证布尔值True:同一DIV中存在两个按钮的XPath逻辑AND,xpath,selenium,logical-operators,Xpath,Selenium,Logical Operators,我有一个XPath表达式,它使用以下内容正确验证布尔值True: //div[starts-with(@id, 'toolbar')]//div[starts-with(@id, 'button')]//a/span[text() = 'Update'] and //div[starts-with(@id, 'toolbar')]//div[starts-with(@id, 'button')]//a/span[text() = 'Save'] 这很好,但它不能断言这两个元素是否包含在同一个D
//div[starts-with(@id, 'toolbar')]//div[starts-with(@id, 'button')]//a/span[text() = 'Update'] and //div[starts-with(@id, 'toolbar')]//div[starts-with(@id, 'button')]//a/span[text() = 'Save']
这很好,但它不能断言这两个元素是否包含在同一个DIV中,这正是我试图在Selenium脚本中使用的
如果//div[以(@id,'toolbar')开头]
是匹配的div元素,我如何断言这两个元素:
//div[以(@id,'button')开头]///a/span[text()='Update']
及
//div[以(@id,'button')开头]///a/span[text()='Save']
是否包含在其中?以下内容可以隔离我的目标容器,但我希望答案能够使用
DIV>A>SPAN>文本
,如原始问题所示:
//div[以(@id,'toolbar')开头][contains(div,'Update')和contains(div,'Save')]
不幸的是,没有提供输入XML,但我想这就是您搜索的内容:
//div[starts-with(@id, 'toolbar') and div[starts-with(@id, 'button')]/a/span[. = 'Update'] and div[starts-with(@id, 'button')]/a/span[. = 'Save']]
我认为这就是您正在寻找的XPath:
//div[starts-with(@id, 'toolbar') and //div[starts-with(@id, 'button')]//a/span[text() = 'Update'] and //div[starts-with(@id, 'button')]//a/span[text() = 'Save']]