'xpath to extract the text in selenium
Need help in extracting the case id, would be great help
<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>
Need to extract 412312513
out of this
Solution 1:[1]
You can use following-sibling
to get text node value from p tag as follow:
//*[@class="note-title"]/following-sibling::p
OR
Using css selector
.note.note-info h4 + p
Example with selenium
txt = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//*[@class="note-title"]/following-sibling::p'))).text
OR selenium with css selector
txt = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.note.note-info h4 + p'))).text
#imports
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |