如何将 70 与 70 (100%) 分开,其中 70 和 (100%) 通过 <br>
链接 Selenium 标签?
结构如下:
<a href="/report/campaigns/698/sent" class=""> 70<br> (100%)</a>
我正在使用的代码是:
String[] REP=new String[1];
String Repor= driver.findElement(By.xpath("//html[1]/body[1]/section[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[5]/table[1]/tbody[1]/tr[1]/td[6]")).getText();
REP=Repor.split("");
System.out.println("REP "+REP[0]);
我得到的输出是:7
最佳答案
Xpath 很疯狂,但为了解决您的问题,我认为这可能就像在 split() 函数中的引号之间添加空格一样简单。应该是
REP=Repor.split(“ “)
澄清后编辑:字符串Repor正在设置换行符。因此,以下代码应分别找到“70”和“(100%)”。
String lines[] = Repor.split("\\r?\\n");
则 lines[0]
为“70”,lines[1]
为“(100%)”。这是你想要的吗?
关于javascript - 如何通过selenium从由 <br> 标签分隔的元素中提取部分文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55197733/