我想收到所有新产品和发布的文字我正在尝试这个
driver.findElement(By.xpath(".//*[@id='iselmf-folder-detail']/h2/span")).getText();
但它正在打印文件夹
<h2 class="iselmf-h2-icon">
<span>Folder:</span>
All New Products and Launches
</h2>
我想收到所有新产品和发布的文字我正在尝试这个
driver.findElement(By.xpath(".//*[@id='iselmf-folder-detail']/h2/span")).getText();
但它正在打印文件夹
<h2 class="iselmf-h2-icon">
<span>Folder:</span>
All New Products and Launches
</h2>
Look at the HTML tags
<span>Folder:</span>
The /span indicates that this is the end of the span, so if you're using the span as the identifier then it will only return folder.
The parent element of the span is the h2 tag. So to get everything between h2 and /h2 tags you need to do this -
driver.findElement(By.xpath(".//*[@id='iselmf-folder-detail']/h2")).getText();
Two ways to do this,
1) driver.findElement(By.xpath(".//*[@id='iselmf-folder-detail']/h2")).getText();
2) Get the text from both and then concatenate it, something like
String firstblock = driver.findElement(By.xpath(".//*[@id='iselmf-folder-detail']/h2")).getText();
String secondblock = driver.findElement(By.xpath(".//*[@id='iselmf-folder-detail']/h2/span")).getText();
String finaltext= firstblock+secondblock;
The text is in the
<h2>
tag, not the<span>
tag. Try