簡體   English   中英

需要轉換列表<WebElement>成字符串數組進行字符串比較

[英]Need to convert list<WebElement> into String array for string comparison

目標:我想比較 Excel 中國家代碼對應國家名稱的列表。 Excel 表格的每列中都有國家代碼和國家名稱,以“,”(逗號)分隔。 我已經通過下面的代碼來解決這個問題。

String codes= hashmap.get("Country code"+i);
String countryname=hashmap.get("Country Name"+i);
String[] eachCNCODE= codes.split(",");
String[] eachCountry=countryname.split(",");

eachCNCODE & eachCountry 數組具有預期的內容。 現在我想將其與網頁中的內容進行比較。 所以我使用列表獲取如下國家代碼和國家名稱的網頁元素。

List<WebElement> countrycodes=driver.findElements(By.xpath("//*[@id='TBL_QryRslts']/tbody/tr/td[4")
List<WebElement> countryNames=driver.findElements(By.xpath("//*[@id='TBL_QryRslts']/tbody/tr/td[5]/div/a")

現在我想將 eachCNCODE 與國家/地區代碼進行比較。 想將List<WebElement>轉換為 String 數組,然后我想比較每個 . 請幫我解決這個問題

您可以使用以下代碼:

List<WebElement> countrycodes=driver.findElements(By.xpath("//*[@id='TBL_QryRslts']/tbody/tr/td[4")
List<String> strings = new ArrayList<String>();
for(WebElement e : countrycodes){
    strings.add(e.getText());
}

希望它會幫助你。

暫無
暫無

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

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