Reputation: 103
driver = webdriver.Chrome()
URL= 'https://modernhousevn.com/collections/new-arrival/products/giuong-ngu-mh-21'
driver.get(URL)
sleep(1)
des = wait.until(EC.visibility_of_element_located((By.XPATH, "//strong[text()='Chất liệu :']/.."))).get_attribute('innerText')
print(des)
My expected result is ['Khung : Khung Gỗ thông - Vạt giường gỗ thông', 'Da PU hoặc vải bố cao cấp nhập khẩu', 'Mousse : D40/35 theo tiêu chuẩn xuất khẩu']
Upvotes: 0
Views: 87
Reputation: 2538
<p>
contain 'Chất liệu'
, back to parent<p>
and parent's class is not panel-body
, back to parent<ul>
, find all <li>
in the <ul>
sleep(1)
target = driver.find_element(By.XPATH, "//strong[contains(text(),'Chất liệu')]/..")
while target.tag_name != 'p' and target.find_element(By.XPATH, "./..").get_attribute("class") != 'panel-body':
target = target.find_element(By.XPATH, "./..")
des = target.find_elements(By.XPATH, './following-sibling::ul[1]/li')
print([d.text for d in des])
output
['Khung : Khung Gỗ thông - Vạt giường gỗ thông', 'Da PU hoặc vải bố cao cấp nhập khẩu', 'Mousse : D40/35 theo tiêu chuẩn xuất khẩu ']
Upvotes: 1
Reputation: 51
Try this xpath to find the text which contains it
(By.XPATH,"//strong[contains(text(),'Chất liệu')]"); hope it will work!
Upvotes: 0
Reputation: 812
Replace below lines of code.
des = wait.until(EC.visibility_of_element_located((By.XPATH, "//strong[text()='Chất liệu :']/.."))).Text;
print(des)
Upvotes: 0