Home > database >  XPath- XPath is Printing Repeating Value
XPath- XPath is Printing Repeating Value

Time:03-11

I want to get the "data-id" value for each row of this webpage.

I copied the XPath of the first row, however, it just prints the value of the "data-id" from the first row x times. Expected result should be the data-id of each row gets its own data-id printed enter image description here

Expected Output- "514" "515" "516" ... ...

import time
from selenium import webdriver
driver = webdriver.Chrome()

driver.get('https://www.abstractsonline.com/pp8/#!/10517/sessions/@timeSlot=Apr08/1')
page_source = driver.page_source
element = driver.find_elements_by_xpath('.//li[@]')
for el in element:
    id=el.find_element_by_xpath('/html/body/div[1]/div[2]/div/div/div[2]/div[2]/div/div[2]/div[2]/ul/li[1]/div[1]/div[1]/h1').get_attribute("data-id")
    print(id)

CodePudding user response:

Try something like this:

import time
from selenium import webdriver
driver = webdriver.Chrome()

driver.get('https://www.abstractsonline.com/pp8/#!/10517/sessions/@timeSlot=Apr08/1')
//page_source = driver.page_source
element = driver.find_elements_by_xpath('.//li[@]//h1')
for el in element:
    id=el.get_attribute("data-id")
    print(id)
  • Related