Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium XPath:沿路径传递属性值_Selenium_Xpath - Fatal编程技术网

Selenium XPath:沿路径传递属性值

Selenium XPath:沿路径传递属性值,selenium,xpath,Selenium,Xpath,我想知道使用xpath是否可以实现以下目标 鉴于: <label for="pt1:sc">Select Country</label> <select id="pt1:sc">....</select> 要求: 我想使用单个xpath表达式查找select元素,如下所示, bcs ID是动态的,在属性“for”中始终可用 //标签[text='Select Country']/@for//*[@id=@for] 我们可以在xpath中为la

我想知道使用xpath是否可以实现以下目标

鉴于:

 <label for="pt1:sc">Select Country</label>
 <select id="pt1:sc">....</select>
要求:

我想使用单个xpath表达式查找select元素,如下所示, bcs ID是动态的,在属性“for”中始终可用

//标签[text='Select Country']/@for//*[@id=@for]

我们可以在xpath中为label的属性传递attribute valuehere,沿着查找元素的路径进一步传递

请不要建议使用同胞、子女、id或selenium get属性等进行替代


谢谢,

我不确定它将如何与您的实际html配合使用,但它适用于问题中的示例:

//label[text()='Select Country'][@for=//select/@id]

您可以使用类似的方法选择一个元素,该元素的属性值引用位于另一个元素中的另一个属性:

//*[@id=//label[text()='Select Country']/@for]