[英]Selenium webdriver : List is not generic; it cannot be parameterized with arguments `<WebElement>` type
[英]How to fix "The type List is not generic; it cannot be parameterized with arguments <String>" error in cucumber selenium JAVA
我嘗試使用數據表並實現我的函數來從這個 Cucumber 數據表中獲取值,我使用了 List< List< String >> 但它不起作用!
public void myfunction(DataTable dt) 拋出 Throwable {
List> list = dt.asList(String.class);
driver.findElement(By.id("name")).sendKeys(list.get(0).get(0));
driver.findElement(By.id("age")).sendKeys(list.get(0).get(1));
driver.findElement(By.id("nphone")).sendKeys(list.get(1).get(0));
driver.findElement(By.id("address")).sendKeys(list.get(1).get(1));}
使用Header我們可以以非常干凈和精確的方式實現數據表,並且考慮到數據表如下所示 -
And fill up the first & last name form with the following data
| First Name | Last Name |
| Tom | Adam |
| Hyden | Pointing |
public void myfunction(DataTable table) throws Throwable {
List<Map<String, String>> list = table.asMaps(String.class,String.class);
driver.findElement(By.id("name")).sendKeys(list.get(0).get("First Name"));
driver.findElement(By.id("age")).sendKeys(list.get(0).get("Last Name"));
driver.findElement(By.id("nphone")).sendKeys(list.get(1).get("First Name"));
driver.findElement(By.id("address")).sendKeys(list.get(1).get("Last Name"));
}
實現規則 -下面是 2 個片段,最有趣的是第一個片段,該片段表明該方法的參數是 DataTable 數據表。 該代碼段建議您應將 DataTable dataTable 參數替換為以下任一參數:
- List<E>
- List<List<E>>
- List<Map<K,V>>
- Map<K,V>
- Map<K, List<V>>
它還告訴我們每種類型,E、K、V 必須是以下任何一種類型:
請檢查您的進口。 我錯誤地下載了 java.awt.list。 當我導入 java.util.list 時它起作用了。
喜歡 :
import java.util.list;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.