Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NinaSalimi/6500b9981a41c345c0c10d5ac87ee6a7 to your computer and use it in GitHub Desktop.
Save NinaSalimi/6500b9981a41c345c0c10d5ac87ee6a7 to your computer and use it in GitHub Desktop.
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")
element.click()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment