根據你的代碼,你似乎已經使用cssSelector(driver.findElement)識別出了表格元素,然後試圖打印它的所有內容,但它不起作用。你已經從表格到tr/td的等級,然後打印它的文本。此外,因爲在你的情況下,將返回多個元素,所以你有使用driver.findElements而不是driver.findElement。嘗試使用下面的代碼,您可能需要根據您的要求修改一點點。
// Get all the table row elements from the table
List<WebElement> allRows = driver.findElements(By.xpath("//table[@class='branded-fares-flights']//tr"));
// And iterate over them and get all the cells
for (WebElement row : allRows) {
List<WebElement> cells = row.findElements(By.tagName("td"));
// Print the contents of each cell
for (WebElement cell : cells) {
System.out.println(cell.getText());
//Or try below code
//System.out.println(cell.getAttribute("innerHTML"));
}
請說明您的具體問題或添加額外的細節,以確切地突出你所需要的。正如目前所寫,很難確切地說出你在問什麼。請參閱[問]頁面以獲得澄清此問題的幫助。 – JeffC
當你進入這個網站時,你從例如巴黎到柏林製作一本書 ,然後你選擇一個變性日期然後返回日期,然後點擊搜索,所以你看到兩個我想要帶它們並在控制檯中打印的表格所有 –