簡體   English   中英

如何在方法中創建方法以創建並單擊Selenium中的Web元素

[英]How to create a method within a method to create and click on a web element in Selenium

我試圖單擊Selenium中的Web鏈接。 該Weblink已在該方法內部創建,但是在if else語句中無法訪問,因此發生錯誤。

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時,就會發生這種情況。

這是代碼

 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();
        }
        //}




    }

基本上,如何在if else語句中創建Weblink。 是否可以調用創建另一個相同Web鏈接的方法? 任何幫助都會很棒。

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

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

viewLink2.click()   // or anything else you need to do with it

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM