如何在将 id 分配给字符串后将 id 附加到 url
How to append the id to the url after assigning the id to the String
场景:我需要将 id 附加到 url。
我做了什么:
我从 table 中获取了最后一个 ID 并将其存储在列表中:
然后我得到id的文本并存储在String
.
List<WebElement> id = driver.findElements(By.xpath("(//table[contains(@class,'mat-table')]//tr/td[1])[last()]"));
int rowsize = id.size();
for(int i=0;i<rowsize;i++)
{
String text = id.get(i).getText();
System.out.println("Get the id:"+text);
然后我使用该文本并将其附加到 URL
String confirmationURL = "https://test-websites.net/#/email?type=confirm";
String newurl = confirmationURL+"&id=text";
= **这部分我将文本作为 id 给出......这是
错误,我需要输入我从列表中获得的 ID ....**
driver.get(newurl);
所以基本上 url 应该是这样的:https://test-websites.net /#/email?type=confirm&id=47474
有人可以就应该做什么提供意见吗?
您可以创建新的 URL 列表,并可以使用 add
方法追加文本。
List<WebElement> id = driver.findElements(By.xpath("(//table[contains(@class,'mat-table')]//tr/td[1])[last()]"));
String confirmationURL = "https://test-websites.net/#/email?type=confirm";
List<String> newurls = new ArrayList<String>();
int rowsize = id.size();
for(int i = 0; i < rowsize; i++) {
String text = id.get(i).getText();
System.out.println("Get the id:"+text);
newurls.add(confirmationURL + "&id=" + text);
}
成功执行此代码后,您将得到一个 newurls
列表,其 URL 以来自 //table[contains(@class,'mat-table')]//tr/td[1])[last()]
xpath 的 id 结尾。
场景:我需要将 id 附加到 url。
我做了什么: 我从 table 中获取了最后一个 ID 并将其存储在列表中:
然后我得到id的文本并存储在String
.
List<WebElement> id = driver.findElements(By.xpath("(//table[contains(@class,'mat-table')]//tr/td[1])[last()]"));
int rowsize = id.size();
for(int i=0;i<rowsize;i++)
{
String text = id.get(i).getText();
System.out.println("Get the id:"+text);
然后我使用该文本并将其附加到 URL
String confirmationURL = "https://test-websites.net/#/email?type=confirm";
String newurl = confirmationURL+"&id=text";
= **这部分我将文本作为 id 给出......这是
错误,我需要输入我从列表中获得的 ID ....**
driver.get(newurl);
所以基本上 url 应该是这样的:https://test-websites.net /#/email?type=confirm&id=47474
有人可以就应该做什么提供意见吗?
您可以创建新的 URL 列表,并可以使用 add
方法追加文本。
List<WebElement> id = driver.findElements(By.xpath("(//table[contains(@class,'mat-table')]//tr/td[1])[last()]"));
String confirmationURL = "https://test-websites.net/#/email?type=confirm";
List<String> newurls = new ArrayList<String>();
int rowsize = id.size();
for(int i = 0; i < rowsize; i++) {
String text = id.get(i).getText();
System.out.println("Get the id:"+text);
newurls.add(confirmationURL + "&id=" + text);
}
成功执行此代码后,您将得到一个 newurls
列表,其 URL 以来自 //table[contains(@class,'mat-table')]//tr/td[1])[last()]
xpath 的 id 结尾。