Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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
Indexing Robotframework通过索引选择元素_Indexing_Element_Selenium Webdriver_Robotframework - Fatal编程技术网

Indexing Robotframework通过索引选择元素

Indexing Robotframework通过索引选择元素,indexing,element,selenium-webdriver,robotframework,Indexing,Element,Selenium Webdriver,Robotframework,基本上,我正在搜索一种语法,可以用来选择共享相同名称、属性和属性的元素 我在考虑通过索引选择它们。(不幸的是Xpath不起作用,因为它是一个动态元素。) 因此,我有一个页面,其中元素Add显示两次,两个元素都添加/抛出不同的值。但它们都有相同的ID、属性和名称。在我的测试中,我需要选择第一个Add,然后选择另一个 ${add attributes row} //*[@data-bind="click: function() { $parents[1].addItem($par

基本上,我正在搜索一种语法,可以用来选择共享相同名称、属性和属性的元素

我在考虑通过索引选择它们。(不幸的是Xpath不起作用,因为它是一个动态元素。)

因此,我有一个页面,其中元素
Add
显示两次,两个元素都添加/抛出不同的值。但它们都有相同的ID、属性和名称。在我的测试中,我需要选择第一个
Add
,然后选择另一个

${add attributes row}          //*[@data-bind="click: function() { 
$parents[1].addItem($parents[1]
    .attributes()[$parentContext.$index()]) }", index=1]


${add attributes row_2}     //*[@data-bind="click: function() { 
$parents[1].addItem($parents[1]
    .attributes()[$parentContext.$index()]) }", index=2]

有没有办法通过索引来选择它们?

如果找到一个XPath同时选择了它们,可以通过将XPath放在括号中对整个XPath应用谓词。例如,//a选择整个DOM中的所有锚点。(//a)[4]选择在DOM中找到的第四个锚点。您还可以使用last和position函数选择相对索引,例如倒数第二个锚点(//a)[last()-1]

第一次尝试这样的定位器:

xpath=(//*[@data-bind="click: function() {$parents[1].addItem($parents[1].attributes()[$parentContext.$index()]) }"])[1]
第二次尝试这样的定位器:

xpath=(//*[@data-bind="click: function() {$parents[1].addItem($parents[1].attributes()[$parentContext.$index()]) }"])[2]

看这个

谢谢。好东西。这正是我想要的答案。