2013-09-05 34 views
1

我想要一個可以打印包含show/id的頁面中的所有鏈接的硒Java RC測試腳本。Selenium RC-打印所有包含文本的鏈接

我想這

int servicecount= selenium.getXpathCount("xpath=//a[contains(@href,'show/id')]").intValue(); 
for(int servicecnt=1;servicecnt<=servicecount;servicecnt++) 
{ 
    String some_container=selenium.getText("xpath= //a[contains(@href,'show/id')["+servicecnt+"]"); 
    System.out.println(some_container); 
} 

這是行不通的。請建議解決方案。

+1

能否請您發佈一些例子鏈接?你什麼意思不起作用? – vidit

+2

「這不起作用」......你得到什麼錯誤? –

+0

感謝您的答覆..示例鏈接:https://control.crucial.com.au/myservices/show/id/8160和錯誤19:43:47.068信息 - 命令請求:getText [xpath = // a [包含(@ href,'show/include')包含(@ href,'show/id')[1],]會話b0ba523c7d48455e8798b70d3dc5b1fc 19:43:48.227信息 - 結果:錯誤:無效xpath [2]:// a [會話b0ba523c7d48455e8798b70d3dc5b1fc 失敗:虛擬服務器檢查 – Shari

回答

1

the spec說,

NOTE: The location path //para[1] does not mean the same as the location path /descendant::para[1] . The latter selects the first descendant para element; the former selects all descendant para elements that are the first para children of their parents.

這意味着,你需要使用後一種方法:

selenium.getText("xpath=/descendant::input[contains(@href,'show/id')]["+servicecnt+"]"); 
+0

嗨,它仍然給我錯誤,19:47:32.886 INFO - 命令請求:getText [xpath = // a [包含(@ href,'show/id')] [2],]會話90d7089a9556482fad3f09dc0e347fb4 19:47:33.931信息 - 得到的結果:錯誤:元素xpath = // a [包含(@ href,'show/id')] [2]沒有在會話90d7089a9556482fad3f09dc0e347fb4中找到 失敗: – Shari

+0

@ShariHaridas啊哈!抱歉,是我的錯。我只看到語法錯誤,並沒有進一步思考。現在我編輯了一個好的解決方案我的答案。 –

+0

@Slanec ..非常感謝..這很好.. – Shari

相關問題