我以为这会很简单,但事实并非如此。所以,请有人帮助我执行以下操作: 我需要从以下 html 中获取号码:
<ol class="competition-standings">
<li class="list-item row">
<div class="column large-4 competition-standings-user ellipsis">
<div class="column large-2 small-3 competition-standings-data">
<strong>1133</strong>Posted
前往接机 1133
尝试了以下操作:
Select tipsnumber = new Select(findElement(By.xpath("correct xpath")));
tipsnumber.getFirstSelectedOption().getText();
System.out.println(tipsnumber);
还有这个
WebElement tipsnumber = driver.findElement(By.xpath("correct xpath"));
tipsnumber.getAttribute("value");
System.out.println(tipsnumber);
对于双方都没有获得号码1133
提前谢谢
最佳答案
您选择使用 Xpath 选择器有什么原因吗? 就我个人而言,我会使用如下的 CSS 类型选择器
WebElement tipsnumber = driver.findElement(By.cssSelector("Strong"));
System.out.println(tipsnumber.getText());
>>1133
关于java - 从元素中选择数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46972160/