xpath提取selenium中的文本

xpath to extract the text in selenium

在提取案例 ID 方面需要帮助,这会很有帮助

    <div class="note note-info"><h4 id="note-label-CreateCaseUploadDoc:Display_Process_Combination1:RequestID" class="note-title">A new request is created successfully</h4><p id="
    ">412312513</p></div></div>

需要从中提取 412312513

您可以使用 following-sibling 从 p 标签中获取文本节点值,如下所示:

//*[@class="note-title"]/following-sibling::p

使用 css 选择器

.note.note-info h4 + p

硒示例

txt = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//*[@class="note-title"]/following-sibling::p'))).text

OR selenium with css 选择器

txt = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.note.note-info h4 + p'))).text

#进口

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC