Skip to content

Instantly share code, notes, and snippets.

@NinaSalimi
NinaSalimi / gist:6500b9981a41c345c0c10d5ac87ee6a7
Created June 22, 2018 15:04
How can I iterate through a list of items and extract a specific part using Selenium and Python
from selenium import webdriver
from selenium import webdriver
chrome_path=r"G:\My Drive\chrome_driver\chromedriver_win32\chromedriver.exe"
driver=webdriver.Chrome(chrome_path)
driver.get('https://meshb.nlm.nih.gov/treeView')
sidebar = driver.find_element_by_xpath("/html/body/div[2]/div")
i=1
for i in range(16): # since I have 16 div(s)
sidebar.find_elements_by_xpath("/html/body/div[2]/div/div[i]")
element = driver.find_element_by_xpath("/html/body/div[2]/div").find_element_by_xpath("/html/body/div[2]/div/div[i]").find_element_by_xpath("//*[@class='ng-scope']/span")