2014-12-02 68 views
0

我想點擊Selenium中的一個web鏈接。 weblink已經在方法內部創建,但是它在if語句中無法訪問,所以發生錯誤。如何在一個方法內創建一個方法來創建並點擊Selenium中的一個web元素

So what I have tried to do is create a new weblink that refers to the same piece of text. This piece of text is "View" which opens up a new table in the UI. 

但是,爲了創建此webelement,我需要從參數中獲取信息。這是在最初在方法中創建webelement時發生的情況。

下面是代碼

public void rejectOrRecallPayments(CreditTransferContext ct) { 
        listPayments.click(); 

        if(isNotBlank(ct.getRecallReason()) || isNotBlank(ct.getRejectReason())) { 
        final WebElement viewLink = getViewLinkFromDisplayTable(resultTable, 
    ct.getOriginatorIBAN(), ct.getAmount()); 
        System.out.println("ct.getOriginatorIBAN() is "+ct.getOriginatorIBAN()); 
        System.out.println("ct.getAmount() is " +ct.getAmount()); 



       if(isNotBlank(ct.getRecallReason())){ 
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
       //This is my attempt to create another "viewLink" in the if else statement 
       final WebElement viewLink2 = getViewLinkFromDisplayTable(resultTable,  ct.getOriginatorIBAN(), ct.getAmount()); 
       viewLink2.click(); 
       ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 






       recallPayment.click();     
       viewCTPage.recallCT().recallCT(ct);  
      }else if(isNotBlank(ct.getRejectReason())){ 
       rejectPayment.click(); 
       viewCTPage.rejectCT().reject(ct); 
      } 
      listPayments.click(); 
     } 
     //} 




    } 

基本上,我怎麼可以創建一個網絡鏈接的,如果else語句內。是否可以調用創建另一個相同的Web鏈接的方法? 任何幫助將是偉大的。

回答

0

這與Selenium無關,這純粹是一個Java問題!

WebElement viewLink2; 
if(...) { 
    viewLink2 = getViewLinkFromDisplayTable(resultTable,  ct.getOriginatorIBAN(), ct.getAmount()); 
    ... 
} 

viewLink2.click() // or anything else you need to do with it 
相關問題