您可以通过运行javascript使用
this.browserbot.findElement('/html/body/div/div//input')以下命令获得该代码:当然,这取决于源语言,但这将是这样的(在perl中,未经测试):
#first count the number of inputs with idsmy $count = $selObj->get_xpath_count('/html/body/div/div//input[@id]');#build a javascript that iterates through the inputs and saves their IDsmy $javascript;$javascript .= 'var elements = [];';$javascript .= "for (i=1;i<=$count;i++)";$javascript .= " elements.push(this.browserbot.findElement('/html/body/div/div/input['+i+']').id);";#the last thing it should do is output a string, which Selenium will return to you$javascript .= "elements.join(',');";my $idString = $selObj->get_eval($javascript);我一直认为应该有一个更直接的方法来执行此操作,但是我还没有找到它!
*根据注释进行 *编辑 ,for循环计数应从1开始并包含
$count,而且findElement行在输入之前仅需要一个正斜杠。
EDIT2 根据进一步的评论添加一个完全不同的想法:
附加到每个页面上的Selenium javascript包括一个称为的函数
eval_xpath,该函数返回给定查询的DOM元素数组。听起来像您想要的吗?
这就是我认为javascript的样子(再次未经测试):
var elements = eval_xpath('/html/body/div/div//input',this.browserbot.getCurrentWindow().document);var results = [];for (i=0;i<elements.length;i++){ results.push(elements[i].id);}results.join(',');


