2014-09-11 36 views
0

我有發生在碼的碼CSS或XPath正則表達式的webdriver

driver.findElement(By.cssSelector("#lmv-dialog-add-id-_newFundAllocation-targetAllocation-88-F03 >td.tright > a.lmv-show")).click(); 

88是可變的。無論是否有88,99,12或任何其他數字,如何修改代碼的代碼被搜索?

另外。在相同名稱的三個元素xpath上:

id('lmv-dialog-add-id-_newFundAllocation-targetAllocation-88-F01')/x:td[3]/x:a 
id('lmv-dialog-add-id-_newFundAllocation-targetAllocation-88-F02')/x:td[3]/x:a 
id('lmv-dialog-add-id-_newFundAllocation-targetAllocation-88-F03')/x:td[3]/x:a 

我想單擊第三項。對於這88是可變的,我想這樣做可以爲任何數值出現在這個地方。

+0

和我有新的思路和新的問題。 如何繪製這個表達式的參數88? – grandecalvo 2014-09-11 12:29:00

回答

0

嘗試用下面的XPath

"//*[contains(@id,'lmv-dialog-add-id-_newFundAllocation-targetAllocation')]/td[3]/a[@class='lmv-show']" 
0

你可以嘗試的XPath starts-with()ends-with()功能的組合:

//*[ 
    starts-with(@id, 'lmv-dialog-add-id-_newFundAllocation-targetAllocation-') 
     and 
    ends-with(@id, '-F11') 
    ] 
/td[contains(@class, 'tright'] 
/a[contains(@class, 'lmv-show'] 

邊注:上面的示例顯示了在模擬的XPath CSS類選擇的簡化版本。如有必要,您可以在以下鏈接之一中使用更合適的方法。

+0

不幸的是,無論是這種方式還是其他任何方式都不希望dzaiałać。變量88由所有會話保存,因此可以將其從xpath/css中提取出來?怎麼樣? – grandecalvo 2014-09-11 12:32:40

+0

感謝您的鏈接。幫助過我。我用xpath包含另一個記錄。再次感謝大家的幫助。 – grandecalvo 2014-09-12 13:47:09