2017-09-25 173 views
0

我如何跳過錯誤並繼續下一個迭代for loop,我粘貼了下面的代碼,我在嘗試的是,我試圖從網站下載多個PDF,我已使用linkText-FullText PDF這是可用於所有PDF exept之一,所以循環失敗,程序停止。硒,java,測試

Error: Exception in thread "main" 
org.openqa.selenium.NoSuchElementException: no such element: Unable to 
locate element: {"method":"link text","selector":"Fulltext PDF"} 
(Session info: chrome=60.0.3112.113) 
+2

哪裏是你的代碼? – NarendraR

+0

信息不夠清楚嗎?沒有符合條件的元素。檢查您的代碼和頁面上的屬性,看看它們是否匹配 –

+0

String printLink; \t \t \t \t嘗試{ \t \t \t \t \t Printlink進行= d.findElement(By.linkText( 「全文PDF」))的getAttribute(的 「href」); \t \t \t \t} \t \t \t \t \t \t \t \t趕上(NoSuchElementException異常E){ \t \t \t \t \t Printlink進行= 「NO_DATA_FOUND」; \t \t \t \t} – SarathChandar

回答

2

您可以使用try catch塊跳過下面給出的錯誤。

for(;;){ 

    try{ 

      //code to click on link text 

    } 
    catch(NoSuchElementException ex){ 

    } 
} 
0

您可以使用任何循環條件像,而與嘗試捕捉連續執行處理異常

,而(真或在此條件){

try{ 

     // your code here 

    }catch(Exception e){ 

    } 

}

((這裏的條件;){

try{ 

     // your code here 

    }catch(Exception e){ 

    } 

}