selenium
元素的输出是
res = webDriverService.getDriver().findElements(By.xpath("//*[@id='main_content']/div/div[2]/h2/span")).get(0).getText();
res
的结果是这样的字符串:
A relationship
A play partner
Friendship
Events
我想知道如何将所有这些设置在一行中,如
A relationship,A play partner,Friendship,Events
所以,我该怎么做?
答案 0 :(得分:2)
您需要做的就是使用字符串操作替换换行符,
:
System.out.println(res.replace("\n",","));
答案 1 :(得分:0)
只需更换换行符?像这样:
res = res.replace("\n",",").replace("\r","");